我目前正在开发一个项目,其中,我从服务器获取数据并在数组中添加(推送)以进行进一步处理。它的工作很棒。 当我使用来自服务器的数据向阵列添加外部数据时,我遇到了问题。
var quantity= ItemsValue[1];
$scope.product = [];
$http.get(___).success(function(data) {
$scope.greeting = data ;
$scope.product.push($scope.greeting);
}
我想推动"数量"使用" $ scope.greeting"。我已经尝试了不同的东西,比如连接但是失败了。
我想要数组的数据是这样的。例如
$ scope.product = [{" greeting.name":" abc"," greeting.price":" 50", "量":" 1" }]
名称和价格来自服务器和数量,作为额外数据添加到Array。
<tbody >
<tr ng-repeat="greeting in product" ><!-- -->
<td class="cart_product">
<img src={{greeting.Image}} alt="book image" ></td>
<td class="cart_description">
<h4>{{greeting.Name}}</h4></td>
<td class="cart_price">
<p>Rs. {{greeting.Cost}}</p>
</td>
<td class="cart_quantity">
<div class="cart_quantity_button">
<a class="cart_quantity_up" href=""> + </a>
<input class="cart_quantity_input" type="text" name="quantity" value="Itemsquantity" autocomplete="off" size="2">
<a class="cart_quantity_down" href=""> - </a>
</div>
</td>
<td class="cart_total">
<p class="cart_total_price">Rs. {{greeting.Cost}}</p>
</td>
<td class="cart_delete">
<a class="cart_quantity_delete" ng-click="removeItem($index)"><i class="fa fa-times"></i></a>
</td>
</tr>
</tbody>
这是客户端的代码。
任何方式将这些东西推到一起......
答案 0 :(得分:1)
您可以通过创建新属性
将其添加到对象中var quantity = ItemsValue[1];
$scope.product = [];
$http.get(___).success(function(data) {
$scope.greeting = data;
$scope.greeting.quantity = quantity;
$scope.product.push($scope.greeting);
}