正在查找dojo.store和dijit.Tree覆盖REST的示例
我正在寻找一个使用正在查找dojo.store和dijit.Tree覆盖REST的示例,rest,dojo,Rest,Dojo,我正在寻找一个使用dojo.store和dijit.Tree而不是REST的端到端示例 有许多现有的示例使用较旧的DojoAPI,dojo.data.api,但缺少使用dojo.storeapi的示例 是不是因为dijit.Tree还不能完全支持dojo.store? 如果是这样,我是否需要使用dojo.data.ObjectStore包装来封装dojo.store,以便与dijit.tree一起使用 我看到了通过扩展StoreFileCache解决此问题的一个示例: 这是推荐的选择,还是我应
dojo.store
和dijit.Tree
而不是REST的端到端示例
有许多现有的示例使用较旧的DojoAPI,dojo.data.api
,但缺少使用dojo.store
api的示例
是不是因为dijit.Tree
还不能完全支持dojo.store
?
如果是这样,我是否需要使用dojo.data.ObjectStore
包装来封装dojo.store
,以便与dijit.tree
一起使用
我看到了通过扩展StoreFileCache解决此问题的一个示例:
这是推荐的选择,还是我应该
a) 坚持使用dojo.data.api
直到dijit.Tree
直接支持dojo.store
,或者
b) 使用dojo.data.ObjectStore
包装器
谢谢DTK网站上现在有一个教程,似乎几乎完全涵盖了这个主题 然而,据我所知,链接到某个对象而不给出答案被认为是一种糟糕的做法,一般的想法是,不要使用
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;
}
});
值得注意的是,在本例中,我们对数据的外观进行了一些假设。你需要知道你的孩子是如何联系和定制下面的方法来达到这个目的的,但是希望你自己能清楚地知道如何做到这一点
您现在也可以继续使用
dojo.data
API,但这种方法确实感觉更加轻量级。它需要从堆栈中取出几层,并定制一个dojo.store
,基于store的存储要容易得多。鉴于您概述的两个选项,我想说的是您对不同API的了解程度
- store更轻,也许更容易理解,但是包装器增加了一些开销。如果你认为你的项目会持续很长时间,这可能是最好的方式
- data是一个遗留API,最终将被淘汰。如果您的项目是短期的,并且仅基于dijit.Tree,那么这可能是您目前的最佳选择