我一直没有被捕获TypeError:无法为以下行设置未定义的属性“1”:
data.rows[j].experiment[experimentNo] = {
"experimentName": {
"goal": goal_entry,
"strategy": strategy_entry,
"experiment_name": experiment_name,
"hypothesis": hypothesis_entry,
"audience": audience_entry,
"kpi": kpi_entry,
"pages": pages_entry,
"experiment_link": expt_link_entry,
"status": status_entry,
"test_brief_link": test_brief_entry
}
}
我对此很新,并且我尝试根据其他帖子进行更改,例如先设置一个空数组,但似乎没有任何效果。请注意,我实际上是在尝试获取数据并对其进行操作以生成所需的输出。请参阅以下内容,了解其所属的整个ajax请求:
$.ajax({
type: "GET",
url: "url",
dataType: 'json',
success: function(data) {
var teams = Object.keys(data.rows).length;
for (j = 0; j < teams; j++) {
var teamid = data.rows[j].id;
if (entryid == teamid) {
var experimentNo = Object.keys(data.rows[j].doc.experiment).length;
var experimentList = data.rows[j].doc.experiment;
data.rows[j].experiment[experimentNo] = {
"experimentName": {
"goal": goal_entry,
"strategy": strategy_entry,
"experiment_name": experiment_name,
"hypothesis": hypothesis_entry,
"audience": audience_entry,
"kpi": kpi_entry,
"pages": pages_entry,
"experiment_link": expt_link_entry,
"status": status_entry,
"test_brief_link": test_brief_entry
}
}
}
}
}
});
json输出示例:
{
"total_rows": 4,
"offset": 0,
"rows": [
{
"id": "218db2ac87c373d8b015e1f3d0f37a1c",
"key": "218db2ac87c373d8b015e1f3d0f37a1c",
"value": {
"rev": "2-453783d12591c400ff0283a1bc6755ae"
},
"doc": {
"_id": "218db2ac87c373d8b015e1f3d0f37a1c",
"_rev": "2-453783d12591c400ff0283a1bc6755ae",
"business_unit": "china",
"team_name": "china2",
"team_number": "china2",
"experiment": {
"experimentname1": {
"goal": "goal1",
"strategy": "strategy1",
"exptname": "exptname1",
"hypothesis": "hypothesis1",
"audience": "audience1",
"kpi": "kpi",
"pages": "pages1",
"exptlink": "exptlink1",
"status": "status1",
"testbrief": "testbrief1"
}
}
}
},
{
"id": "4683dd4fa0446efc3ed7dd24a94aabc8",
"key": "4683dd4fa0446efc3ed7dd24a94aabc8",
"value": {
"rev": "1-57471567a501230e5405b0e518dc6cf0"
},
"doc": {
"_id": "4683dd4fa0446efc3ed7dd24a94aabc8",
"_rev": "1-57471567a501230e5405b0e518dc6cf0",
"business_unit": "cloud",
"team_name": "clou2",
"team_number": "clou2",
"experiments": ""
}
},
{
"id": "77f6455bbb80db982d1a2c3604cfbe90",
"key": "77f6455bbb80db982d1a2c3604cfbe90",
"value": {
"rev": "1-5e1cdb086f97c13175d8bb8a4a569dc3"
},
"doc": {
"_id": "77f6455bbb80db982d1a2c3604cfbe90",
"_rev": "1-5e1cdb086f97c13175d8bb8a4a569dc3",
"business_unit": "bluemix",
"team_name": "Bluemix1",
"team_number": "Bluemix1",
"experiments": ""
}
},
{
"id": "9382855b57442ab3e054a4a366fa6cfd",
"key": "9382855b57442ab3e054a4a366fa6cfd",
"value": {
"rev": "1-223523bc661e179d94ae63dbeda55cf5"
},
"doc": {
"_id": "9382855b57442ab3e054a4a366fa6cfd",
"_rev": "1-223523bc661e179d94ae63dbeda55cf5",
"business_unit": "china",
"team_name": "china1",
"team_number": "china1",
"experiments": ""
}
}
] } 谢谢!