从数据库获取数据并绑定到表,但我想在结果数据中添加额外的列, 我从数据库获取名称值,但从ui我想将额外的列城市推到表
视图
<table>
<thead>Name</thead>
<thead>City</thead>
<tr ng-repeat="r in result">
<td>
{{r.Name}}
</td>
<td>
{{r.City}}
</td>
</tr>
</table>
角
//实际上这些数据来自数据库,是硬编码的
$scope.rvm = [{
Name: 'M',
},
{
Name: 'B'
}
]
$scope.result = $scope.rvm;
$scope.result.push({
City: "Hyd"
}, {
City: "Guntur"
});
我试过这个但是城市值增加到下一行。但我想添加表格正确的格式
答案 0 :(得分:0)
你可以尝试:
$scope.result = [];
var city = "hbd"; // what ever value you want
angular.forEach($scope.rvm, function (value, key) {
$scope.result.push({
Name: value.Name,
city : city
});
});
答案 1 :(得分:0)
您正在向阵列推送另外两个对象。所以你最终会得到一个包含4个元素的数组。前两个只包含一个名称。最后两个只包含一个城市。这不是你想要的。你想要的是添加一个属性到数组中的现有对象:
$scope.result[0].City = "Hyd";
$scope.result[1].City = "Guntur";