从各个地方获取有关嵌套json是否在extjs中可用的冲突信息。 NB使用Sencha Architect可能会让事情变得复杂......
我有一个客户端json对象通过store / ajax代理返回。我无法访问第一级以外的任何内容。
JSON看起来像这样:
{
"client": {
"0": {
"id": "12345",
"type_id": "3",
"association_id": "0",
"is_active": "1",
"manager_id": "2",
"business_name": null,
"has_payroll": "0",
"business_proprietor_contact_id": null,
"date_created": "1358893243",
"date_modified": "1358893243"
},
"contacts": [
{
"id": "1",
"client_id": "12345",
"contact_id": "1",
"is_primary": "0",
"display_priority": "0",
"relationship": "Client",
"friendly_name": "Homer",
"contact": [
{
"id": "1",
"surname": "Mr.",
"first_name": "Homer",
"middle_name": "J",
"last_name": "Simpson",
"client_id": "12345",
"date_created": "1356038714",
"date_modified": null
},
{
"addresses": [
{
"id": "1",
"contact_id": "1",
"address_id": "16",
"is_mailing_address": "0",
"is_primary_address": "0",
"display_priority": "0",
"address": {
"0": {
"id": "16",
"address": "5 Dirt Rd",
"address2": "",
"city": "TAXMASTER",
"state": "NY",
"zip_code": "454545",
"country": "USA",
"other": null,
"phone": null,
"fax": null,
"display_priority": null,
"is_mailing_address": "1"
},
"data": [
{
"id": "10",
"label": "Phone",
"value": "BUT WHO WAS",
"date_created": "1356104685",
"date_modified": "1357142782",
"user_id": null,
"display_priority": null,
"client_id": null,
"contact_id": null,
"account_id": null,
"business_id": null,
"address_id": "16",
"is_deleted": "0"
},
{
"id": "14",
"label": "Fax",
"value": "simile",
"date_created": "1356557379",
"date_modified": "1357142782",
"user_id": null,
"display_priority": null,
"client_id": null,
"contact_id": null,
"account_id": null,
"business_id": null,
"address_id": "16",
"is_deleted": "0"
},
{
"id": "17",
"label": "Also Known as:",
"value": "DUDE",
"date_created": "1357141357",
"date_modified": "1357142782",
"user_id": null,
"display_priority": null,
"client_id": null,
"contact_id": null,
"account_id": null,
"business_id": null,
"address_id": "16",
"is_deleted": "0"
}
]
}
},
{
"id": "6",
"contact_id": "1",
"address_id": "26",
"is_mailing_address": "0",
"is_primary_address": "0",
"display_priority": "0",
"address": {
"0": {
"id": "26",
"address": "1 Lift Road",
"address2": "",
"city": "Tony Beach",
"state": "KS",
"zip_code": "15151",
"country": "USA",
"other": null,
"phone": null,
"fax": null,
"display_priority": null,
"is_mailing_address": "0"
},
"data": [
{
"id": "18",
"label": "Phone:",
"value": "cool phone number",
"date_created": "1357141527",
"date_modified": "1357141527",
"user_id": null,
"display_priority": null,
"client_id": null,
"contact_id": null,
"account_id": null,
"business_id": null,
"address_id": "26",
"is_deleted": "0"
},
{
"id": "19",
"label": "Note:",
"value": "cool note",
"date_created": "1357141527",
"date_modified": "1357141527",
"user_id": null,
"display_priority": null,
"client_id": null,
"contact_id": null,
"account_id": null,
"business_id": null,
"address_id": "26",
"is_deleted": "0"
}
]
}
},
],
"data": [
{
"id": "1",
"label": "asdf",
"value": "dfdfefefefef",
"date_created": "1356038714",
"date_modified": "1356040822",
"user_id": "2",
"display_priority": "0",
"client_id": null,
"contact_id": "1",
"account_id": null,
"business_id": null,
"address_id": null,
"is_deleted": "0"
},
{
"id": "2",
"label": "asfd",
"value": "152151",
"date_created": "1356038714",
"date_modified": "1356040822",
"user_id": null,
"display_priority": "2",
"client_id": null,
"contact_id": "1",
"account_id": null,
"business_id": null,
"address_id": null,
"is_deleted": "0"
},
]
}
]
},
{
"id": "7",
"client_id": "12345",
"contact_id": "11",
"is_primary": "0",
"display_priority": "0",
"relationship": "None",
"friendly_name": "Mary Jane",
"contact": {
"0": {
"id": "11",
"surname": "",
"first_name": "Mary Jane",
"middle_name": "",
"last_name": "Simpson",
"client_id": null,
"date_created": "1357145795",
"date_modified": null
},
"7": {
"addresses": [
{
"id": "11",
"contact_id": "11",
"address_id": "33",
"is_mailing_address": "0",
"is_primary_address": "0",
"display_priority": "0",
"address": {
"0": {
"id": "33",
"address": "33 Street",
"address2": "",
"city": "NY",
"state": "NY",
"zip_code": "06830",
"country": "USA",
"other": null,
"phone": null,
"fax": null,
"display_priority": null,
"is_mailing_address": "0"
},
"data": [
{
"id": "31",
"label": "Fax:",
"value": "asdfasdf",
"date_created": "1357145905",
"date_modified": "1357145939",
"user_id": null,
"display_priority": null,
"client_id": null,
"contact_id": null,
"account_id": null,
"business_id": null,
"address_id": "33",
"is_deleted": "0"
},
{
"id": "32",
"label": "Fax:",
"value": "sadfsadf",
"date_created": "1357145905",
"date_modified": "1357145905",
"user_id": null,
"display_priority": null,
"client_id": null,
"contact_id": null,
"account_id": null,
"business_id": null,
"address_id": "33",
"is_deleted": "0"
}
]
}
}
],
"data": [
{
"id": "29",
"label": "Phone:",
"value": "asdfsadf",
"date_created": "1357145833",
"date_modified": "1357145833",
"user_id": "2",
"display_priority": null,
"client_id": null,
"contact_id": "11",
"account_id": null,
"business_id": null,
"address_id": null,
"is_deleted": "0"
},
{
"id": "30",
"label": "Email:",
"value": "dsfgdsfg",
"date_created": "1357145855",
"date_modified": "1357145855",
"user_id": "2",
"display_priority": null,
"client_id": null,
"contact_id": "11",
"account_id": null,
"business_id": null,
"address_id": null,
"is_deleted": "0"
}
]
}
}
}
],
"notes": [
{
"id": "5",
"client_id": "12345",
"label": "This is a HomerHomer Note",
"value": "This is from Homer's Dashboard Notes.",
"contact_id": null,
"address_id": null,
"account_id": null,
"account_data_id": null,
"account_credential_id": null,
"payment_id": null,
"contact_log_id": null,
"user_id": "2",
"bill_id": null,
"is_deleted": "0",
"date_created": "1357148256",
"date_modified": "1357148256"
}
]
}
}
根据https://stackoverflow.com/a/8318589/183254嵌套的JSON不可用。根据{{3}}, 可用,但必须采用某种格式。
我根据API文档格式进行了一些测试:
{
results: 2000,
rows: [
{ id: 1, firstname: 'Bill', occupation: 'Gardener', cool: {neat: 'wow'} },
{ id: 2, firstname: 'Ben' , occupation: 'Horticulturalist' },
]
}
随着这个进来,我可以从tpl调用所有内容。特别是,cool.neat
打印wow
。但是,将cool
更改为cool:[{neat:'wow}]
会中断。所以似乎嵌套json部分工作 - 可能只是部分因为我做错了。
我的想法是,对api执行单个请求并收集所有需要的信息,解析它并将其发送到组件而不是为所需的每组数据创建代理是有意义的。我可能错了......
除了需要的指导/面子,我还有两个问题:
1)尝试做我正在做的事情是否可行/可行?即尝试使用单个请求收集多个组件的数据?
2)有没有办法从tpl调试数据?
这是通过Sencha Architect
的extjs 4.1感谢。
答案 0 :(得分:1)
我有同样的问题。我可以解决它的唯一方法(我尝试映射和其他几个解决方案)基本上有一个主存储和子库。从ajax获取信息并将其带入主商店。有一个"加载"监听器和加载时,检查信息是否需要传递给其他商店。
将所有子目录autoload属性设置为false,并且永远不会加载它们。
即:
load: function(t,records,successful,eOpts) {
var substores [{store: nameOfStore, root: rootPropInTheJson},
{store...etc...etc..];
for (var i = 0; i < substores.length; i++) {
if (pathtoroot* != undefined) {
substores[i].store.add(pathtojsonroot)
}
}
}
至少,这就是我认为你的意思。如果这是你的意思,那么是的,我发现它很实用,而且我不知道第二个问题的答案。