gpt4 book ai didi

rest - 在 REST 上寻找带有 dijit.Tree 的 dojo.store 示例

转载 作者:行者123 更新时间:2023-12-01 04:53:45 24 4
gpt4 key购买 nike

我正在寻找通过 REST 使用 dojo.storedijit.Tree 的端到端示例。

有许多现有示例使用旧的 dojo api,dojo.data.api,但使用 dojo.store api 的示例很少。

dijit.Tree还没有完全支持dojo.store的原因吗?如果是这样,我是否需要使用 dojo.data.ObjectStore 包装器来封装 dojo.store 以便与 dijit.tree 一起使用?

我看到了一个通过扩展 StoreFileCache 来解决这个问题的例子: http://dojo-toolkit.33424.n3.nabble.com/New-object-store-and-dijit-Tree-td2680201.html

这是推荐的选项,还是我应该

a) 坚持使用 dojo.data.api 直到 dijit.Tree 直接支持 dojo.store,或者

b) 使用dojo.data.ObjectStore 包装器

谢谢

最佳答案

现在 DTK 网站上有一个教程似乎涵盖了这个主题。

http://staging.dojotoolkit.org/documentation/tutorials/1.6/store_driven_tree/

但是,据我所知,在不给出答案的情况下链接到某些内容被认为是一种糟糕的做法,一般的想法是,与其使用 dojo.data.ObjectStore 环绕它,然后可能推通过 ForestStoreModel,您可以简单地扩充基于 dojo.store 的商店,以添加树将查找的方法。这是教程中的一个简单示例:

usGov = new dojo.store.JsonRest({
target:"data/",
mayHaveChildren: function(object){
// see if it has a children property
return "children" in object;
},
getChildren: function(object, onComplete, onError){
// retrieve the full copy of the object
this.get(object.id).then(function(fullObject){
// copy to the original object so it has the children array as well.
object.children = fullObject.children;
// now that full object, we should have an array of children
onComplete(fullObject.children);
}, onError);
},
getRoot: function(onItem, onError){
// get the root object, we will do a get() and callback the result
this.get("root").then(onItem, onError);
},
getLabel: function(object){
// just get the name
return object.name;
}
});

值得注意的是,在这种情况下,我们对数据的外观做了一些假设。您需要了解您的 child 如何关联并为此目的定制以下方法,但希望您自己已经相当清楚如何做到这一点。

您现在也可以只使用 dojo.data API,但这种方法确实感觉更轻量级。它从堆栈中取出几个层,并且自定义基于 dojo.store 的商店要容易得多。

关于rest - 在 REST 上寻找带有 dijit.Tree 的 dojo.store 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6654251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com