2015-04-01 66 views
0

我在Umbraco 7的自定義節中有一個多級樹,其中根節點始終是國家/地區。獲取自定義節樹中的父節點

  • 丹麥
    • 項目1
    • 項目2
  • Sweeden
    • 項目1
    • 項目2
  • 挪威
    • 項目1
    • 項目2

現在,丹麥的第2項工作時,我想獲得的根節點的節點ID(丹麥),這樣我知道我在哪個國家/地區編號。

是否有任何JavaScript API遞歸回節點級別,並獲得最頂級的擴展?

在此先感謝。 喬納斯

回答

1

我所做的是使用editorState
(我跑一把umbraco 7.5.7)

angular.module("umbraco").controller("Client.Controller", 
    function ($scope, editorState) { 

    // Get the rootNode out of the path. 
    var rootNode = editorState.current.path.split(",")[1]; 
}); 

由於路徑包含當前節點所在的整個結構,因此第二個第一個節點將是根節點。


另一種解決方案可能是這樣的:
(有沒有這個測試我自己)
https://our.umbraco.org/forum/developers/extending-umbraco/73796-how-to-get-the-parentid-of-the-current-node-in-custom-tree-using-angularjs

其中以簡單的方式規定:

注入APPSTATE和treeService到您的角控制器

這將獲得當前樹的最頂端節點:
var rootNode = appState.getTreeState(「currentRootNode」);

這將獲得自定義樹中當前選定的節點
var selectedNode = appState。getTreeState( 「selectedNode」);

0

這樣做將與剃刀最簡單的方法:

var parentNode = CurrentPage.AncestorOrSelf(1); 

這會給你當前頁面的根節點,您可以根據需要訪問根結點的屬性:

int id = parentNode.Id; 
+0

由於我在我的後端部分的角度控制器工作,剃刀是可悲的不是一個選項。因此,我需要JS方式:)但謝謝。 – 2015-04-01 08:37:51