2012-02-15 123 views
0

使用sencha touch 2,我試圖使用json proxy呈現嵌套列表。 JSON的樣子Sencha Touch JSONPReader

[ 
    { 
    "start": "0" 
    }, 
    { 
    "format": "json" 
    }, 
    ....... 
    { 
    "GetFolderListing": [ 
     { 
      "folder": { 
       "total": 0, 
       "id": "Calendar", 
       "name": "Calendar", 
       "unread": 0, 
      } 
     }, 
     { 
      "folder": { 
       "total": 0, 
       "id": "Contacts", 
       "name": "Contacts", 
       "unread": 0, 
      } 
     }, 
    ....... 

我想用GetFolderListing.folder.name作爲displayField 我的店看起來像

Ext.define('foo.store.FolderListing', { 
extend: 'Ext.data.TreeStore', 
require: ['foo.model.FolderListing'], 
config: { 
    model: 'foo.model.FolderListing', 
    recursive: true, 
    proxy: { 
    type: 'jsonp', 
    url: 'http://localhost/?xx=yy&format=json', 
    callbackKey: "jsoncallback", 
    reader: { 
     type: 'json', 
     rootProperty: 'GetFolderListing', 
     record: 'folder' 
    } 
} 
} 
}); 

現在我得到的是一個錯誤 遺漏的類型錯誤:無法讀取property'id'undefined

任何人都可以提供關於如何解決這個問題或更好地調試的見解,或者如何進行自定義分析並將項目傳回商店?

由於

======== 更新 - 爲了使rootProperty在讀取器工作,JSON必須是一個JSONObject而非JSON陣列例如

{ 
"GetFolderListing": [ 
    { 
     "folder": { 
      "total": 0, 
      "id": "Contacts", 
      "name": "Contacts", 
      "unread": 0, 
      "leaf": "true" 
     } 
    }, 
    { 
     "folder": { 
      "total": 0, 
      "id": "Conversation Action Settings", 
      "name": "Conversation Action Settings", 
      "unread": 0, 
      "leaf": "true" 
     } 
    }, 
    ....... 

回答

0

你的JSON看起來像一個數組。錯誤消息意味着代碼嘗試訪問未定義的變量或屬性的屬性。

我的第一個猜測是,讀者沒有正確配置該數組類型的JSON格式。

+0

是的,你是對的,JSON需要爲第一組兄弟姐妹映射尋址以使rootProperty工作。謝謝 ! – pjaol 2012-02-16 03:15:15