Sencha Touch 1.1.1 嵌套 JSON 存储加载
大家好,我希望有人能帮助我解决这个问题,虽然这是一些该死的初学者问题,但已经得到了回答,但我真的很困惑,我向你们保证,我阅读了所有答案帖子,但仍然无法让它发挥作用。
我正在使用 Sencha Touch 1.1.1 并尝试让此 Store 加载嵌套的 JSON 数据。代码如下:
Ext.regModel("UserData", {
hasMany : [{
name : "id",
type : "integer",
},{
name : "username",
type : "string",
},{
name : "password",
type : "string",
}]
});
var userdata =
{"users": [
{
"id": 16,
"username": "[email protected]",
"password": "bla",
}, {
"id": 17,
"username": "[email protected]",
"password": "bla",
}
]
};
var myStore = new Ext.data.Store({
model : 'UserData',
data : userdata,
proxy : {
type : 'ajax',
reader : {
type : 'json',
root : 'users' // not working
}
}
});
var myList = new Ext.List ({
fullscreen : true,
store : myStore,
grouped : false,
itemTpl : '<div>{username}</div>'
});
返回未捕获的类型错误:参数列表的类型错误。当我使用外部数组包装器重写 JSON 时,它可以工作,但使用错误的根(不是用户)时,我确实看到了与 root:'' 值一起使用的示例。
var userdata =
[ {"users": [
{
"id": 16,
"username": "[email protected]",
"password": "bla",
}, {
"id": 17,
"username": "[email protected]",
"password": "bla",
}
]
} ];
我缺少什么?
Hi guys I hope someone can help me with this I´m really stuck although it´s some damned beginner question that has already been answered and I assure you I read all of the answer Posts but still can´t get it to work.
I´m using Sencha Touch 1.1.1 and try to get this Store loaded with nested JSON data. Here´s the code:
Ext.regModel("UserData", {
hasMany : [{
name : "id",
type : "integer",
},{
name : "username",
type : "string",
},{
name : "password",
type : "string",
}]
});
var userdata =
{"users": [
{
"id": 16,
"username": "[email protected]",
"password": "bla",
}, {
"id": 17,
"username": "[email protected]",
"password": "bla",
}
]
};
var myStore = new Ext.data.Store({
model : 'UserData',
data : userdata,
proxy : {
type : 'ajax',
reader : {
type : 'json',
root : 'users' // not working
}
}
});
var myList = new Ext.List ({
fullscreen : true,
store : myStore,
grouped : false,
itemTpl : '<div>{username}</div>'
});
Returns Uncaught Type Error: Arguments list has wrong type. When I rewrite the JSON with an outer Array wrapper, it works, but with wrong root (not users) I definitly saw examples where this worked with the root:'' value.
var userdata =
[ {"users": [
{
"id": 16,
"username": "[email protected]",
"password": "bla",
}, {
"id": 17,
"username": "[email protected]",
"password": "bla",
}
]
} ];
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我没有记错的话,在您的“UserData”模型中,它应该是
fields
而不是hasMany
。尝试将 json 数据放入单独的 json 文件中,并在商店代理中找到路径。
我测试了它,在这里工作得很好。这是我的完整代码。
If I am not mistaken, in your "UserData" model, it should be
fields
instead ofhasMany
.And try putting your json data in a separate json file and locate the path in your store's proxy.
I tested it and it's working fine here. Here is my full code.