这是我的json数据:
{
"seendata": {
"count": 2,
"rows": [
{
"id": 8,
"contactCount": 2,
"group": {
"id": 7,
"groupname": "group1",
"createdAt": "2017-11-16T10:53:12.000Z",
"updatedAt": "2017-11-16T10:53:12.000Z"
}
}
]
},
"alldata": [
{
"id": 7,
"groupname": "group1",
"createdAt": "2017-11-16T10:53:12.000Z",
"updatedAt": "2017-11-16T10:53:12.000Z"
},
{
"id": 8,
"groupname": "group2",
"createdAt": "2017-11-16T10:54:41.000Z",
"updatedAt": "2017-11-16T10:54:41.000Z"
}
]
}
我的api代码:
exports.getNewGroup = function (req, res) {
var globalObj={};
ContactGroup.findAndCountAll({
attributes: ['id', [sequelize.fn('COUNT', sequelize.col('group.id')),
'contactCount'
]],
include: [{
model: Group,
}],
}).then(seenData => { globalObj.seendata=seenData;return Group.findAll();})
.then(function (data) {
globalObj.alldata=data;
return res.status(200).send(globalObj);
}).catch(function (err) {
return res.status(400).send(err.message);
});
};
我的角度客户端控制器代码:
$http({
method: 'GET',
url: '/api/getnewgroup'
})
.then(function (response) {
$scope.groups = response.data.seendata.rows;
$scope.alldata = response.data.alldata;
console.log($scope.groups);
}, function (response) {
window.location.href = '/';
});
我的玉文件:
tr(ng-repeat='group in groups')
td {{group.groupname}}
td {{group.contactCount}}
我想显示 contactCount 值以及我想在前端显示 alldata.groupname 值吗?
帮助我!
我正确地收到了{{group.contactCount}},但我没有收到来自 alldata.groupname
的{{group.groupname}}如何获得?两个值以及如何传递多个范围并在ng-repeat中使用?
答案 0 :(得分:0)
最好将allData输入$ scope.alldata = response.data.alldata;
$http({
method: 'GET',
url: '/api/getnewgroup'
})
.then(function (response) {
$scope.groups = response.data.seendata.rows;
$scope.allData = response.data.alldata;
console.log($scope.groups);
}, function (response) {
window.location.href = '/';
});
在您的Jade文件中
<tr ng-repeat='group in groups track by $index'>
<td>
<span ng-repeat='data in alldata'>data.groupname</span>
</td>
<td>group.contactCount</td>
</tr>
在rows $ index的帮助下,你也可以获取allData的数据。希望它能起作用