如何在Extjs的组合框中传递树存储

时间:2019-07-18 08:35:26

标签: extjs extjs6 treestore

我有一个组合框,它需要一个树存储作为其存储。 我已经尝试过下面的代码,但无法正常工作。

Ext.define('DemoGroupCombo', {
    extend: 'Ext.data.TreeStore',
    fields: ['text', 'value'],
    proxy: {
        type: 'rest',
        url: '../SamplePaging/GetComboTree',
        //data: groupStoreData,
        reader: {
            type: 'json',
            rootProperty: 'children'
        }
    }
});

来自api的预期json结果:

var groupStoreData =  
//new Ext.data.TreeStore({
//  root:
{
    expanded: true, children: [
        {
            //checked: false, text: "All", expanded: true, children: [
            //  {
            checked: false, text: "Numbers", expanded: true, children: [
                { checked: false, text: '1', value: '1', leaf: true },
                { checked: true, text: '2', value: '2', leaf: true },
                { checked: false, text: '3', value: '3', leaf: true },                  
                {
                    checked: false, text: '4', value:'4', leaf: true
                }
            ]
        }
    ]
    //}]
}

组合框:

{
    xtype: 'combobox',          
    selModel: {
       selType: 'checkboxmodel'
    },
    queryMode: 'local', 
    displayField: 'text',
    valueField: 'value',        
    store: { type: 'DemoGroupCombo' }
}

现在我正在显示此错误消息:

  

错误:[Ext.createByAlias]无法识别的别名:store.DemoGroupCombo

2 个答案:

答案 0 :(得分:1)

您需要为商店指定别名:

Ext.define('DemoGroupCombo', {
    extend: 'Ext.data.TreeStore',
    alias: 'store.DemoGroupCombo',
    fields: ['text', 'value'],
    proxy: {
        type: 'rest',
        url: '../SamplePaging/GetComboTree',
        //data: groupStoreData,
        reader: {
            type: 'json',
            rootProperty: 'children'
        }
    }
});

答案 1 :(得分:0)

我得到了解决方案,这是进行ajax代理调用的方法。

Ext.define('DemoGroupCombo', {
    extend: 'Ext.data.TreeStore',
    alias: 'store.DemoGroupCombo',
    autoLoad: true,
    proxy: {
        type: 'ajax',
        useDefaultXhrHeader: false,
        actionMethods: { create: "POST", read: "POST", update: "POST", destroy: "POST" },
        headers: {
            'accept': '*/*'
        },
        async: false,
        limitParam: false,
        startParam: false,
        pageParam: false,       
        url: '../SamplePaging/GetComboTree',
        reader: {
            rootProperty: "children",
            type: 'json'
        }
    },
    defaultRootProperty: "children",
    root: {
        expanded: true
    }
});
相关问题