【问题标题】:Retrieve data with extjs 3.4 panel + dataview + jsonstore使用 extjs 3.4 panel + dataview + jsonstore 检索数据
【发布时间】:2012-12-03 12:24:55
【问题描述】:

我正在尝试通过 dataview 显示一些数据,但由于某种原因,我收到了一条空文本消息(无数据)。 这是我的数据视图:

xtype        : 'dataview',
emptyText    : 'No data',
id           : 'cartdata',
multiSelect  : true,
plugins      : new Ext.DataView.DragSelector( { dragSafe : true } ),
store        : new Ext.data.JsonStore({
    url           : '/aecms/user-photos-view/',
    autoLoad      : true,
    root          : 'data',
    fields        : [
    'images'
    ],
    listeners : {
        scope : this,
        load  : function(store) {
            var data = store.reader.jsonData;
            if (data.systemMessage) {
                infoReport(data.systemMessage.title, data.systemMessage.message, data.systemMessage.icon);
            }
        } 
    } 
}),
tpl          : new Ext.XTemplate(
    '<tpl for=".">',
    '<tpl for="images">',
    '<a title="{id}">test</a>',
    '</tpl>',
    '</tpl>'
    )

这是来自php的数据:

{"data":{"images":{"id":"2"}},"status":"success"}

我是 extjs 新手,感谢任何帮助。

【问题讨论】:

    标签: php extjs


    【解决方案1】:

    从外观上看,您没有正确返回 successProperty 值。将您的 php 代码的响应更改为,如下所示。

    您商店中 JsonReader 的默认成功属性为“成功”。 ExtJs 会在你的服务器响应中寻找这个属性。

    http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.JsonReader-cfg-successProperty

    此外,您可能希望将数据作为 json 数组返回,而不是对象。您不需要数据数组中的图像对象。

    服务器响应:

    { "data":[{"id":"2"}], "success":true }
    

    Javascript:

        ...
    store        : new Ext.data.JsonStore({
        url           : '/aecms/user-photos-view/',
        autoLoad      : true,
        root          : 'data',
        fields        : [
        'id'
        ],
        listeners : {
            scope : this,
            load  : function(store) {
                var data = store.reader.jsonData;
                if (data.systemMessage) {
                    infoReport(data.systemMessage.title, data.systemMessage.message, data.systemMessage.icon);
                }
            } 
        } 
    })
    tpl: new Ext.XTemplate(
        '<tpl for=".">',
        '<a title="{id}">test</a>',
        '</tpl>'
    )
    

    【讨论】:

    • 嗯,非常感谢,现在我将深入研究 xtemplate 来解决我的问题。
    猜你喜欢
    • 1970-01-01
    • 2014-09-17
    • 2021-05-13
    • 2020-07-03
    • 1970-01-01
    • 2011-08-28
    • 2012-05-13
    • 2011-06-20
    • 1970-01-01
    相关资源
    最近更新 更多