本文介绍了将响应移到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面给出了一个响应,我需要将程序详细信息移到一个数组中并在表中显示它们.但是我收到未定义的消息,因为programdetails再次是一个数组.我的programdetails存储在newprogramdetails[]
中如果我给ng-repeat,它将给出重复的错误.
I have a response given below, I need to move program details into an array and show them in table. But I am getting undefined message since, programdetails is again an array.my programdetails is stored in newprogramdetails[]
if I give ng-repeat it gives duplicate error.
HTML:
<tr ng-repeat="item in newProgramDetails">
<td>{{newProgramDetails.title}}</td>
<td>{{newProgramDetails.description}}</td>
<td>{{newProgramDetails.createddate}}</td>
<td>{{newProgramDetails.updateddate}}</td>
</select></td>
</tr>
JS:
UserService.getProgram(json).then(function(response) {
$scope.newprograms = response.json.response.data;
for(var i=0;i<$scope.newprograms.length;i++){
newProgramDetails.push($scope.newprograms[i].programdetails);
}
});
JSON:
{
"json": {
"response": {
"servicetype": "4",
"functiontype": "4004",
"statuscode": "0",
"statusmessage": "Success",
"data": [
{
"programdetails": {
"id": 256,
"createddate": "2016-10-07 10:20:48",
"defaultprogram": true,
"description": "This is default program .",
"ppin": "000256",
"apin": "000256",
"owner": true,
"allowscheduling": false,
"points": 0,
"title": "Cakey Bakes Customer default program",
"updateddate": "2016-10-07 10:20:48",
"programtype": "Customer"
}
},
{
"programdetails": {
"id": 257,
"createddate": "2016-10-07 10:20:48",
"defaultprogram": true,
"description": "This is default program .",
"ppin": "000257",
"apin": "000257",
"owner": true,
"allowscheduling": false,
"points": 0,
"title": "Cakey Bakes Vendor default program",
"updateddate": "2016-10-07 10:20:48",
"programtype": "Vendor"
},
"userlist": [
{
"businessuserid": 44,
"businessusername": "rk business New",
"businessusermobile": "00",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": false,
"emailvalidated": false,
"email": "[email protected]",
"upin": "000044"
}
]
}
]
}
}
}
推荐答案
您不需要为此进行循环.
You dont need for loop for this.
解决问题的正确方法是:
Correct approach to solve your issue is:
<tr ng-repeat="item in json.response.data">
<td>{{item.programdetails.title}}</td>
<td>{{item.programdetails.description}}</td>
<td>{{item.programdetails.createddate}}</td>
<td>{{item.programdetails.updateddate}}</td>
</select></td>
</tr>
这篇关于将响应移到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!