Sencha touch 森查触摸屏
使用sencha touch 2,我试图用json代理呈现嵌套列表。 json看起来像Sencha touch 森查触摸屏,sencha-touch,sencha-touch-2,Sencha Touch,Sencha Touch 2,使用sencha touch 2,我试图用json代理呈现嵌套列表。 json看起来像 [ { "start": "0" }, { "format": "json" }, ....... { "GetFolderListing": [ { "folder": { "total": 0, "id": "Calendar",
[
{
"start": "0"
},
{
"format": "json"
},
.......
{
"GetFolderListing": [
{
"folder": {
"total": 0,
"id": "Calendar",
"name": "Calendar",
"unread": 0,
}
},
{
"folder": {
"total": 0,
"id": "Contacts",
"name": "Contacts",
"unread": 0,
}
},
.......
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'
}
}
}
});
我想使用GetFolderListing.folder.name作为显示字段
我的商店看起来像
[
{
"start": "0"
},
{
"format": "json"
},
.......
{
"GetFolderListing": [
{
"folder": {
"total": 0,
"id": "Calendar",
"name": "Calendar",
"unread": 0,
}
},
{
"folder": {
"total": 0,
"id": "Contacts",
"name": "Contacts",
"unread": 0,
}
},
.......
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'
}
}
}
});
现在我得到的只是一个错误
未捕获的TypeError:无法读取未定义的属性“id”
有人能提供关于如何更好地解决这个问题或调试它,或者如何进行自定义解析并将项传递回存储的见解吗
谢谢
========
更新-为了让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"
}
},
.......
您的JSON看起来像一个数组。错误消息表示代码试图访问未定义变量或属性的属性
我的第一个猜测是,没有为该数组类型的JSON格式正确配置读取器。是的,您是对的,JSON需要为第一组同级映射可寻址,才能使rootProperty工作。非常感谢。