Sencha Touch将项插入TreeStore / NestedList

时间:2014-03-24 08:04:50

标签: extjs sencha-touch sencha-touch-2 nested-lists sencha-touch-2.1

有没有办法在TreeStore中插入新记录?

TreeStore是NestedList的数据源,因此在结束时我需要将新项添加到NestedList中

以下是我的示例https://fiddle.sencha.com/#fiddle/4f4

var dataStore;
var dataObj;

Ext.application({
    name: 'testApp',

    launch: function() {
        // data
        dataObj = {
            items: [
                {
                    field1: '1',
                    items: [{
                        field1: '1.1',
                        items: [{
                            field1: '1.1.1 last',
                            leaf: true
                        }, {
                            field1: '1.1.2 last',
                            leaf: true
                        }]
                    }, {
                        field1: '1.2 last',
                        leaf: true
                    }]
                }, 
                {
                    field1: '2',
                    items: [{
                        field1: '2.1 last',
                        leaf: true
                    }, {
                        field1: '2.2 last',
                        leaf: true
                    }]
                }
            ]
        }

        // model
        Ext.define('dataModel', {
            extend: 'Ext.data.Model',
            config: {
                fields: [
                    {name: 'field1', type: 'string'},
                ]
            }
        });

        // TreeStore
        dataStore = Ext.create("Ext.data.TreeStore", {
            storeId: "usersStore",
            model: "dataModel",
            defaultRootProperty: 'items',
            data : dataObj
        });

        // Nestedlist and display
        Ext.create('Ext.NestedList', {
            fullscreen: true,
            displayField: 'field1',
            store: dataStore
        });
    }

});

类似的主题:Sencha Touch 2: Insert into TreeStore/NestedList

谢谢!

1 个答案:

答案 0 :(得分:0)

商店与您的嵌套列表捆绑在一起,因此只需添加新数据即可存储。

    dataObj.items.push({
        field1: '3',
        items: [{
            field1: '3.1 last',
                leaf: true
            }, {
                field1: '3.2 last',
                leaf: true
        }]                    
    });
    dataStore.setData(dataObj);