如何将从ng repeat获得的列表发布到angularjs中的api?
HTML如何将从ng repeat获得的列表发布到angularjs中的api?,angularjs,Angularjs,HTML <body class="res layout-subpage" ng-app="cartApp" ng-controller="cartController"> <table class="table table-bordered"> <thead> <tr> <td class="text-center">Image</td>
<body class="res layout-subpage" ng-app="cartApp" ng-controller="cartController">
<table class="table table-bordered">
<thead>
<tr>
<td class="text-center">Image</td>
<td class="text-left">Product Name</td>
<td class="text-left">Product Id</td>
<td class="text-left">Quantity</td>
<td class="text-right">Unit Price in (₹)</td>
<td class="text-right">Total </td>
</tr>
</thead>
<tbody id="cartItems">
<tr ng-repeat="product in productsInCart">
<td class="text-center">
<a href="product.html"><img width="70px" src="{{product.ProductImage}}" alt="{{product.ProductName}}" title="Xitefun Causal Wear Fancy Shoes" class="img-thumbnail" />
</a>
</td>
<td class="text-left"><a href="product.html">{{product.ProductName}}</a>
</td>
<td class="text-left" ng-model="product.price">{{product.pid}}</td>
<td class="text-left" width="200px">
<div class="input-group btn-block quantity">
<input type="text" name="quantity" value="{{product.qty}}" ng-model="product.qty" ng-text-change="UpdateItemPrice(product)" size="1" class="form-control" />
<span class="input-group-btn">
<button type="submit" data-toggle="tooltip" title="Update" class="btn btn-primary"><i class="fa fa-clone"></i></button>
<button type="button" data-toggle="tooltip" title="Remove" class="btn btn-danger" ng-click="removeProductFromCart(product.pid)" onClick=""><i class="fa fa-times-circle"></i></button>
</span>
</div>
</td>
<td class="text-right" ng-model="products.price">{{product.price}}</td>
<td class="text-right" ng-model="product.itemTotal">{{product.price * product.qty}}
<input type="hidden" ng-model="product.itemTotal" value="{{product.price * product.qty}}" />
</td>
</tr>
</tbody>
</table>
</body>
现在我想在MVC模型中将这些行作为列表发布。
数据成功地从对象中检索并显示在表行中,但我想在控制器中将这多行作为列表发布为MVC模型。基本上,这是一个购物车项目,我需要在服务器上发布。您使用的服务器端堆栈是什么?我使用localstorage以HTML格式呈现此数据。var cartValue=localStorage.getItem(“cartItems”);cartValue='['+cartValue+']';console.log(cartValue);var cartObj=JSON.parse(cartValue)$scope.productsInCart=cartObj;需要将$scope.Order转换为JSON字符串,然后从JSON字符串的第一个和最后一个位置删除“[”和“]”。
$scope.PostCartDataforOffers = function (productsInCart)
{
$scope.productsArray = [];
var tid = parseInt($cookies.get('TenantId'));
angular.forEach(productsInCart, function (value, index) {
value.tp = value.price * value.qty;
$scope.productsArray.push({ pid: value.pid, price: value.price, qty: value.qty, tp: value.tp });
});
$scope.Order = [];
$scope.Order.push({ "ti": tid, "shoppedetail": $scope.productsArray });
var OrderString = JSON.stringify($scope.Order);
var model = OrderString.slice(1, -1);
$http({
headers: { 'Content-Type': 'application/json;charset=utf-8' },
url: "/Cart/Checkout",
method: 'POST',
data: model
})
.then(function (response) {
console.log(response);
});
}
$scope.PostCartDataforOffers = function (productsInCart)
{
$scope.productsArray = [];
var tid = parseInt($cookies.get('TenantId'));
angular.forEach(productsInCart, function (value, index) {
value.tp = value.price * value.qty;
$scope.productsArray.push({ pid: value.pid, price: value.price, qty: value.qty, tp: value.tp });
});
$scope.Order = [];
$scope.Order.push({ "ti": tid, "shoppedetail": $scope.productsArray });
var OrderString = JSON.stringify($scope.Order);
var model = OrderString.slice(1, -1);
$http({
headers: { 'Content-Type': 'application/json;charset=utf-8' },
url: "/Cart/Checkout",
method: 'POST',
data: model
})
.then(function (response) {
console.log(response);
});
}