2012-12-03 40 views
3

我試圖通過數據視圖顯示一些數據的數據,但由於某種原因,我得到一個消息emptytext(無數據)。 這裏是我的數據視圖:獲取與ExtJS的3.4面板+數據視圖+ jsonstore

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

通過它的外觀,你沒有正確返回successProperty值。變化的響應從你的PHP代碼是,如下所示。

的JsonReader對您的商店的默認successProperty是「成功」。 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>' 
) 
+0

好,非常感謝,現在我會挖掘更多關於xtemplate解決我的煩惱。 – Milwater