使用Extjs 3.4面板+数据视图+JSON存储检索数据。

3

我正在尝试通过dataview显示一些数据,但出现了空文本消息(无数据)的原因。以下是我的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的新手,非常感谢任何帮助。

1个回答

1

从外观上看,您没有正确返回successProperty值。请将您的php代码响应更改为以下内容。

您存储器上JsonReader的默认successProperty是“success”。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以解决我的问题。 - Milwater

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接