在DOJO 1.6中创建排序树? [英] Creating sorted tree in DOJO 1.6?

查看:156
本文介绍了在DOJO 1.6中创建排序树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我新来学习dojo,并尝试使用示例代码学习。
使用dojo 1.6



借助示例代码,我创建了一个树





现在我要在根目录上应用排序还有孩子。
在此


I new to learn dojo and trying to learn by it using samples code. Using dojo 1.6

With help of sample codes , I created a tree

now i want to apply sorting on root and also on child. With the help of this sample code , i changed the code

Output is not sorted n but the root folder has changed their position and child is deleted.

Plz help me to resolve this.

My code :

dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dijit.tree.ForestStoreModel");
dojo.require("dijit.Tree");
var data = [ { id: 1, name: "answerTypeLabel",                 type:'scenario',    children:[{_reference: 2}]},
                       { id: 2, name: "acceptRequestLabel",             type:'paragraph',   data: "acceptRequestLabel"},
                       { id: 3, name: "rejectRequestLabel",             type:'scenario',    children:[{_reference: 5},{_reference: 6}]},
                       { id: 4, name: "MoreInformationLabel",       type:'scenario',    children:[{_reference: 7},{_reference: 8}]},
                       { id: 5, name: "rejectRequestStatusLabel",   type:'paragraph',   data: "rejectRequestStatusLabel"},
                       { id: 6, name: "rejectRequestNotCoveredLabel", type:'paragraph',     data: "rejectRequestNotCoveredLabel" },
                       { id: 7, name: "MoreInformationDocumentLabel", type:'paragraph',     data: "MoreInformationDocumentLabel"},
                       { id: 8, name: "MoreInformationDataLabel",   type:'paragraph',   data: "MoreInformationDataLabel"}
                     ];
dojo.addOnLoad(function() {
    var sortableStore = new dojo.data.ItemFileReadStore({
        data: {
              identifier: 'id',
                        label: 'name',
                        items: data 
        }
    });
    var model = new dijit.tree.ForestStoreModel({
        rootLabel: 'Names',
        store: new dojo.data.ItemFileWriteStore({
            data: {
                identifier: 'id',
                items: [],
                label: 'name'
            }
        }) // blank itemsstore
    })
    var tree = new dijit.Tree({
        model: model,
        updateItems: function(items) {
            var self = this;
            console.log('pre', this.model.root.children);

            dojo.forEach(items, function(newItem) {
                console.log('add', newItem);
                try {
                    self.model.store.newItem({
                        id: sortableStore.getValue(newItem, 'id'),
                        name: sortableStore.getValue(newItem, 'name'),
                        type: sortableStore.getValue(newItem, 'type'),
                        data: sortableStore.getValue(newItem, 'data'),

                    });
                } catch (e) {
                    console.log(e);
                }
            });
            console.log('post', this.model.root.children);
            console.log("children: ", this.rootNode.getChildren());

        },
    });
    tree.placeAt(dojo.body());
    sortableStore.fetch({
        query: {
            type:'scenario' 
        },
        sort: [{
            attribute: "name"}],
        onComplete: function(items) {
            console.log(items, 'sorted');
            tree.updateItems(items);

        }
    })
});

Output :

解决方案

The 'Names' origins from you setting 'rootLabel'.

Btw, fiddles have revisions and is simply a paste-bin like feature :)

You need to use the tree model pasteItem to insert referenced items (the 'children' property of each 'newItem').

Otherwise, there's another approach, if you get rid of the '_reference' structure of your data. See: http://jsfiddle.net/GHFdA/1/

这篇关于在DOJO 1.6中创建排序树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆