如何在 AngularJS 中使用 dxTreeView
How to use dxTreeView with AngularJS
你好,我如何使用 dx-tree-view,我在 Home.html 页面的下一个 html 代码中写道:
<div dx-tree-view="treeViewOptions"></div>
在我的 HomeController.js:
$scope.treeViewOptions = {
bindingOptions: {
dataSource: 'myPhoneItems'
},
keyExpr: 'id',
displayExpr: 'caption',
parentIdExpr: 'parentId',
virtualModeEnabled: true
}
我的应用程序有 创建新类别 和 创建新 Phone 按钮,
在创建新 Phone 时, 创建新 phone -form 有 select 框和 类别 ,我将数据保存到 对象数组 中,它看起来像这样:
当我在页面中添加一些 phone 时:
当我将 dataStructure: "plain" 行添加到 $scope.treeViewOptions = {...} - 什么都不显示。
可能有人知道如何正确制作它?感谢您的回答!
您似乎没有指定根项目:
If the dataStructure option is set to 'plain', the widget requires you to specify at least one root item. An item is used as a root item if its parentId field holds 0 or null.
也请参阅此 article。
但在您的示例中,我看不到任何 parentId = 0 或 null
的项目。无论如何,您可以使用任何 parentId 来指定根级别。只需使用 rootValue 选项:
$scope.treeViewOptions = {
//...
rootValue: 1
};
我创建了 the small sample 来展示它的实际效果。
希望对您有所帮助!
你好,我如何使用 dx-tree-view,我在 Home.html 页面的下一个 html 代码中写道:
<div dx-tree-view="treeViewOptions"></div>
在我的 HomeController.js:
$scope.treeViewOptions = {
bindingOptions: {
dataSource: 'myPhoneItems'
},
keyExpr: 'id',
displayExpr: 'caption',
parentIdExpr: 'parentId',
virtualModeEnabled: true
}
我的应用程序有 创建新类别 和 创建新 Phone 按钮,
在创建新 Phone 时, 创建新 phone -form 有 select 框和 类别 ,我将数据保存到 对象数组 中,它看起来像这样:
当我在页面中添加一些 phone 时:
您似乎没有指定根项目:
If the dataStructure option is set to 'plain', the widget requires you to specify at least one root item. An item is used as a root item if its parentId field holds 0 or null.
也请参阅此 article。
但在您的示例中,我看不到任何 parentId = 0 或 null
的项目。无论如何,您可以使用任何 parentId 来指定根级别。只需使用 rootValue 选项:
$scope.treeViewOptions = {
//...
rootValue: 1
};
我创建了 the small sample 来展示它的实际效果。
希望对您有所帮助!