【问题标题】:How to pass treestore in combobox in Extjs如何在 Extjs 的组合框中传递树存储
【发布时间】:2019-07-18 08:35:26
【问题描述】:

我有一个组合框,它需要一个树存储作为它的存储。 我试过下面的代码,但它不起作用。

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

【问题讨论】:

    标签: extjs extjs6 treestore


    【解决方案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'
            }
        }
    });
    

    【讨论】:

    • 是的,我的错误我错过了但仍然没有在存储中获取数据,我什至尝试通过将数据直接传递给数据属性但两种方式 store.data.items 数组都是空的..
    • Sencha 在combobox 中不能轻松使用Ext.data.TreeStore。您需要改用Ext.data.Store 或自行创建Combo Tree Picker
    • 我知道@norbeq,但我们仍然可以将此存储绑定到组合框,然后我们可以将相同的存储用于其选择器,该选择器可以覆盖到树面板。
    • 正如我所说 - 您需要更改组合框选择器。你能附上服务器响应的结果吗?
    • 对不起,我认为我没有完全阅读它..btw 感谢您的回答,我缺少别名..
    【解决方案2】:

    我得到了解决方案,这是进行 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
        }
    });
    

    【讨论】:

    • 这并不能回答您提出的问题
    • 但它会将商店绑定到我想要的组合框
    猜你喜欢
    • 2012-07-18
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多