2014-02-12 110 views
0

這是我迄今爲止,但它似乎並不奏效:更改文本

var dataSource = treeView.dataSource; 
var dataItem = dataSource.get(parseInt($('#nodeId' + '@guid').val(), 10)); 
var node = treeView.findByUid(dataItem.uid); 
treeView.select(node); 
treeView.text(node, "ChangedText"); 

回答

2

您可以用TreeView的text方法改變它,或通過設置對數據項的屬性:

var tree = $("#treeview").kendoTreeView({ 
    dataSource: inlineDefault, 
    loadOnDemand: false 
}).data("kendoTreeView"); 

// change using treeView.findByText and treeView.text 
$("#change").click(function() { 
    var searchString = "Sofas"; 

    $(tree.findByText(searchString)).each(function() { 
     tree.text(this, "Thrones"); 
    }); 
}); 

// change using the data source 
$("#change2").click(function() { 
    var searchString = "Sofas"; 

    var dataItem = tree.dataSource.data()[0].items[1]; 
    dataItem.set("text", "Thrones");  
}); 

你需要的loadOnDemand選項設置爲false搜索樹,因爲當相關分支展開時,才能創建否則DOM元素。

demo