2017-02-28 20 views
0

正在從數據庫中獲取數據,並結合表,但我想添加額外的列到結果數據, 正在從數據庫中獲取的名稱值,但是從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

你是否手動推動城市或者它是輸入控件? – Jenny

+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 
      }); 
}); 
0

你推兩個額外的對象數組。所以,你最終用4個元素的數組。前兩個只包含一個名稱。最後兩個只包含一個城市。這不是你想要的。你想要的是將一個屬性添加到數組中的現有對象:

$scope.result[0].City = "Hyd"; 
$scope.result[1].City = "Guntur"; 
相關問題