Sencha Touch JSONPReader
使用 sencha touch 2,我尝试使用 json 代理渲染嵌套列表。 json 看起来像
[
{
"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 作为显示字段 我的商店看起来
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'
}
}
}
});
现在我得到的只是一个错误 未捕获的类型错误:无法读取未定义的属性“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"
}
},
.......
Using sencha touch 2, am trying to render a nestedlist with json proxy.
The json looks like
[
{
"start": "0"
},
{
"format": "json"
},
.......
{
"GetFolderListing": [
{
"folder": {
"total": 0,
"id": "Calendar",
"name": "Calendar",
"unread": 0,
}
},
{
"folder": {
"total": 0,
"id": "Contacts",
"name": "Contacts",
"unread": 0,
}
},
.......
I want to use GetFolderListing.folder.name as the displayField
My store looks like
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'
}
}
}
});
Right now all i get is an error
Uncaught TypeError: Cannot read property 'id' of undefined
Could anyone provide insight on how to solve this or debug it better or how to do custom parsing and pass items back to a store?
Thanks
========
Update - in order for the rootProperty to work in the reader, the json had to be a jsonobject rather than a json array e.g.
{
"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"
}
},
.......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 JSON 看起来像一个数组。该错误消息意味着代码尝试访问未定义的变量或属性的属性。
我的第一个猜测是读取器没有针对该数组类型 JSON 格式进行正确配置。
Your JSON looks like an array. The error message means that the code tries to access a property of a undefined variable or property.
My first guess would be that the reader is not properly configured for that array type JSON format.