我試圖展示一個配置了遠程數據的Kendo TreeView,但預先填充了直接從html加載的數據的前兩個級別。在Kendo的PushCreate兒童節點HierarchicalDataSource
對於這一點,我想用的劍道的DataSource pushCreate方法將初始元素添加到樹:
homogeneous = new kendo.data.HierarchicalDataSource({
transport: { read: { url: serviceRoot + "/Employees", dataType: "jsonp" } },
schema: {
model: {
id: "EmployeeId",
hasChildren: "HasEmployees"
}
}
});
// Adding root
homogeneous.pushCreate({"EmployeeId":2,"FullName":"Andrew Fuller","HasEmployees":true,"ReportsTo":null});
// Adding children
homogeneous.pushCreate([
{"EmployeeId":1,"FullName":"Nancy Davolio","HasEmployees":false,"ReportsTo":2},
{"EmployeeId":3,"FullName":"Janet Leverling","HasEmployees":false,"ReportsTo":2},
{"EmployeeId":4,"FullName":"Margaret Peacock","HasEmployees":false,"ReportsTo":2},
{"EmployeeId":5,"FullName":"Steven Buchanan","HasEmployees":true,"ReportsTo":2},
{"EmployeeId":8,"FullName":"Laura Callahan","HasEmployees":false,"ReportsTo":2}
]);
$("#treeview").kendoTreeView({
dataSource: homogeneous,
dataTextField: "FullName"
});
然而,元素添加到根級的孩子(你可以看到這運行here)。
有一個schema.model.children
配置來設置保存子元素內的子元素的屬性,我可以一次添加所有,但如果我使用它,那麼dataSource將停止使用遠程數據(您可以看到運行here )。
所以問題是,有沒有辦法使用pushCreate將元素添加爲HierarchicalDataSource中另一個元素的子元素?
不幸的是,這是行不通的!第二級仍然從遠程加載。當您更改HierarchicalDataSource的URL時,您會看到只有父項會被加載。 – leo 2015-08-21 15:11:12