[英]dijit.tree with empty folders
i have created a tree select that shows a dijit.tree in the dropdown. 我创建了一个树选择,该树选择在下拉列表中显示dijit.tree。 Now I do not want the user to select a folder even if it is empty.
现在,我不希望用户选择一个文件夹,即使该文件夹为空。 User should only be able to select the end nodes or leaves.
用户应该只能选择末端节点或叶子。 dijit.tree treats all empty folders as leafs.
dijit.tree将所有空文件夹视为叶子。 how do I get that sorted?
我如何进行排序?
You need to override the _onClick or setSelected methods. 您需要覆盖_onClick或setSelected方法。 This gets complicated if you use the multi-parental model ForestStoreModel.
如果使用多父母模型ForestStoreModel,这将变得很复杂。
See fiddle.net 见fiddle.net
Try doing as such, this will only work for select multiple false: 尝试这样做,这仅适用于选择多个false的情况:
getIconClass: function fileIconClass(item, nodeExpanded) {
var store = item._S,
get = function() {
return store.getValue(item, arguments[0]);
};
// scope: dijit.Tree
if (item.root || get("isDir")) {
if (!item || this.model.mayHaveChildren(item) || get("isDir")) {
return (nodeExpanded ? "dijitFolderOpened" : "dijitFolderClosed");
} else {
return "dijitLeaf";
}
} else {
return "dijitLeaf";
}
},
onClick: function(item, treeNode, e) {
var store = item._S,
get = function() {
return store.getValue(item, arguments[0]);
};
if (get("isDir")) this.set("selectedItems", []);
}
Adapt as you see fit, matching your json data - in particular the isDir , the above works on a sample of json like this 视需要进行调整,匹配json数据-特别是isDir ,以上内容适用于这样的json示例
{
identifier: 'id',
label: 'foo',
items: [
{
id: 'item1',
foo: 'file1',
isDir: false},
{
id: 'item2',
foo: 'emptyDir',
isDir: true},
{
id: 'item3',
foo: 'dir',
isDir: true,
children: [
{
id: 'item3_1',
foo: 'fileInDir',
isDir: false}
]}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.