【问题标题】:store data in a panel将数据存储在面板中
【发布时间】:2011-11-04 13:47:21
【问题描述】:

我创建了一个面板,它必须显示商店的数据,但它什么也没显示。 这是我的面板:

pnl = new Ext.form.FormPanel({
        id          : 'profile',
        renderTo    : 'itemselector',
        items:[{
                xtype       : 'itemselector',
                name        : 'itemselector',
                fieldLabel  : 'Gestion des groupes:',
                imagePath   : 'ext/examples/multiselect/images/',
                multiselects: [{
                        width   : 275,
                        height  : 220,
                        store   : store1,
                        displayField: 'text'
                },{
                        width   : 275,
                        height  : 220,
                        store   : [['10','Ten']]
                }]
        }],
    });

这是我的商店:

store1 = new Ext.data.GroupingStore({
         id         : 'StoreGroupe'
        ,url        : 'st1.php'
        ,reader     : new Ext.data.JsonReader({
                        root            : 'data',
                        totalProperty   : 'rows',
                        id              : 'ReaderGroupes',
                        fields          : [{name:'Gname'}]
                    })
}); 

仅当我使用这样的静态存储时才有效:

 store1 = new Ext.data.ArrayStore({
    data    :  [['1', 'One'], ['2', 'Two'], ['3', 'Three'], ['4', 'Four'], ['5', 'Five'],['6', 'Six']],
    fields  :  ['value','text']
});

【问题讨论】:

    标签: extjs panel store


    【解决方案1】:

    FormPanel 配置为将“文本”字段显示为多选。但是,GroupingStore 中的 JsonReader 不包含“文本”字段。 ArrayStore 之所以有效,是因为为存储定义了一个“文本”字段。

    为 JsonReader 定义一个“文本”字段,并确保服务器返回一个“文本”字段并且它应该可以工作。

    【讨论】:

    • 那么如何在 JsonReader 中定义“文本”字段。
    • @Fares Omrani Try:fields : [{name:'text'}] 而不是当前字段。此外,服务器需要返回带有“文本”字段的 JSON。或者,如果 JSON 包含另一个名称的字段,该字段应映射到 JsonStore 中的“文本”,请尝试 fields : [{name:'text', mapping:'jsonFieldName'}]
    • 我使用了这家商店,但仍然没有显示任何内容: store1 = new Ext.data.GroupingStore({ id : 'StoreGroupe' ,url : 'st1.php' ,reader : new Ext.data .JsonReader({ root : 'data', totalProperty : 'rows', id : 'ReaderGroupes', fields : [{name:'text', mapping:'Gname'}] }) });
    • @Far 听起来可能存在与 JsonReader 对来自服务器的 JSON 数据的期望相匹配的问题。例如,JSON 是否包含一个名为“data”的根字段,其中包含“Gname”字段?如果没有,请删除 root : 'data' 属性。
    • 这是 Json 包含的内容:{success: true, rows:1, data:[{"G_ID":"1","Gname":"defaut"}]}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    • 2011-02-09
    • 2018-02-21
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    相关资源
    最近更新 更多