gpt4 book ai didi

json - Sencha 触摸 : How to get data from complex JSON objects

转载 作者:行者123 更新时间:2023-12-04 19:59:31 26 4
gpt4 key购买 nike

我无法从复杂的 json 对象中检索记录,但我可以在使用 TPL 时获取数据。

请看下面的示例代码:

JSON:

{
"lists": [
{
"title": "Groceries",
"id": "1",
"items": [
{
"text": "contact solution - COUPON",
"listId": "1",
"id": "4",
"leaf": "true"
},
{
"text": "Falafel (bulk)",
"listId": "1",
"id": "161",
"leaf": "true"
},
{
"text": "brita filters",
"listId": "1",
"id": "166",
"leaf": "false"
}
]
}
]

型号:

Ext.regModel("TopModel", 
{
fields: [
{ name: 'title', type: 'string' },
{ name: 'id', type: 'string' },
],
hasMany: [
{ model: 'SubModel', name: 'items' }
],
proxy: {
type: 'ajax',
url : 'test/lists.json',
actionMethods: {
create: 'POST',
destroy: 'POST',
read: 'POST',
update: 'POST'
},
reader: {
type: 'json',
root: function(data) {
return data.lists || [];
}
}
}
});

Ext.regModel("SubModel",
{
fields: [
{ name: 'text', type: 'string'},
{ name: 'listId', type: 'string'},
{ name: 'id', type: 'string'},
{ name: 'leaf', type: 'string'}
]
});

在我的 View 文件中,我定义了如下商店。

this.stores = new Ext.data.Store({
clearOnPageLoad: false,
autoLoad:true,
model:'TopModel',
getGroupString: function(record) {
return record.get('leaf');
}
});
});

我无法检索到 record.get('leaf') 的值,因为它指的是子模型项。当我尝试打印它时,它打印为未定义。

如何访问子属性?这里'items'被列为一个数组。

我尝试使用如下列表显示数据。显示了所有记录,但问题是它是作为一个完整的项目选择的,而不是每个项目的单独列表。

var list = new Ext.List({
cls: 'big-list',
grouped : true,
emptyText: '<div>No data found</div>',
itemTpl: ['<div><tpl for="items">',
'<div>',
'{id} {text}',
'</div>',
'</tpl></div>',
],
store: this.stores,
listeners: {
itemtap: this.onListItemTap,
scope: this
}
});

请帮助我如何让列表项显示为单独的记录。

最佳答案

您可以使用在线 json 解析器(http://json.parser.online.fr/)从解析器数据中解析 json xml 您可以轻松分离对象和数组,并获得您需要的所有数据..我希望这对您有帮助

关于json - Sencha 触摸 : How to get data from complex JSON objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8240455/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com