我有一個dojo.data.ItemFileWriteStore對象,其中的項目包含'children'屬性,該屬性又包含一個children項目數組。我正在存儲一棵樹,並且我需要從此樹中獲取葉節點。我已經寫了一個fetch方法,但它不起作用,給它一個查詢「children:[]」我如何獲取具有children.length 0(葉節點)的數據存儲項目?沒有添加屬性的空數組,如'葉':我的項目布爾顯然會工作,但我寧願沒有額外的屬性。查詢dojo.data.ItemFileWriteStore的屬性屬性(並不那麼容易)
dojo.require(dojo.data.ItemFileWriteStore);
// A tree node with no children, these are the kind I want returned
// from the query!
var rootItem = {
children: []
};
var treeStore = new dojo.data.ItemFileWriteStore({
data: {
items: [rootItem]
}
});
//when dojo reaches one of its inner filtering methods
//there is a point where it calls dojo.some() to see
//which elements in the array to return which match the
//given items attribute, this is where it fails
treeStore.fetch({
query: {children: []},
queryOptions: {deep: true},
onComplete: function(leafItems) {
// All the items with no children here...
}
});
我也試過嵌套屬性的功能無濟於事:
treeStore.fetch({
query: {
children: function(store, item){
return store.getValue(item, 'children').length == 0;
}
},
queryOptions: {deep: true},
onComplete: function(leafItems) {
// All the items with no children here...
}
});
我對數據存儲中的層次數據不太感興趣,但據說Dojo數據存儲支持分層數據。您必須打開分層選項或其他內容。谷歌它,你會發現它。 – 2011-03-30 04:44:31