我有一个web方法,它在每个调用中返回json数据我将此结果推送到$ scope变量,但在ng-repeat内部它不绑定此结果。我的代码有什么问题。请建议。 这是我的代码
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetLocationStockEntries(int LocationId, int ProductId)
{
var jsonText = (dynamic)null;
try
{
if (LocationId > 0)
{
Int64 BusinessUnitId = 0;
using (var db = new repute.Data.ReputEntities())
{
var temp = db.Inventories.Where(p => p.InventoryID == LocationId).FirstOrDefault();
BusinessUnitId = temp == null ? 0 : Convert.ToInt64(temp.BusinessUnitID);
var StockData = db.usp_mvc_InventoryItems_GetAllEntriesByLocation(LocationId, ProductId, BusinessUnitId).Where(x => x.ProjectedQuantityOnHand > 0).ToList();
jsonText = JsonConvert.SerializeObject(new { data = StockData });
}
}
}
catch (Exception ex)
{
}
return jsonText;
}
js:正在调用此Web方法的函数,并将这些结果推送到$ scope变量
function GetStockEntries(loid, pid)
{
return $http.post(serviceURL + "/GetLocationStockEntries", {LocationId: loid, ProductId: pid }).then(
function success(data, status, headers, config) {
var obj = JSON.parse(data.data.d);
debugger
//$scope.result = obj.data;
$scope.result = obj;
angular.forEach($scope.result, function (key) {
$scope.StockList.push(key);
})
},
function error(data, status, headers, config) {
return data;
});
}
HTML:
<table cellpadding="5" cellspacing="0" data-ng-repeat="sTockProduct in ProductList" data-ng-cloak>
<tr>
<td>{{sTockProduct.Name}}
<i class="fa fa-expand" aria-hidden="true" style="color: #000000; text-align: right; margin:5px 0px 0px 10px;" data-ng-click="StockListing(sTockProduct);"></i></td>
</tr>
<tr>
<td>
<table cellpadding="5" cellspacing="0" data-ng-repeat="stockItem in StockList track by $index" data-ng-show = "IsVisible" data-ng-cloak width="100%">
<tr style="border-bottom: 1px solid #ddd; padding-bottom: 5px; margin-bottom: 5px; float: left;">
<td>
<input type="radio" name="groupName" data-ng-value="true" data-ng-model="stockItem.selected[$index]" data-ng-click="onTaskSelect(stockItem,sTockProduct)" />
</td>
<td>
<input type="text" data-ng-model="stockItem.UserInventoryItemID" disabled="" readonly="" style="border: none; background-color: white;">
</td>
<td>
<input type="text" data-ng-model="stockItem.LotNumber" disabled="" readonly="">
</td>
<td>
<!--<input type="text" data-ng-model="stockItem.QuantityOnHand" disabled="" readonly="">-->
<span>{{stockItem.QuantityOnHand}}</span>
<span>{{stockItem.UnitName}}</span>
</td>
<td>
<input type="text" data-ng-model="stockItem.EnteredQuantity" >
</td>
<td>
<input type="text" data-ng-model="stockItem.Description" disabled="" readonly="">
</td>
</tr>
</table>
</td>
</tr>
</table>
答案 0 :(得分:1)
我想问题是你在ng-repeat.try有些事情,如果两个项目中的某些东西相似的话,请检查一个条件。在你的内表中
data-ng-if =&#34; stockItem.ProductID == sTockProduct.ProductID&#34;
应该是这样的:
<table cellpadding="5" cellspacing="0" data-ng-repeat="stockItem in StockList track by $index" data-ng-if="stockItem.ProductID == sTockProduct.ProductID" data-ng-cloak width="100%">
在您的成功中稍作修改:
替换:
$scope.result = obj;
为:
$scope.result = obj.data;