2016-10-17 7 views
0

私はこのメソッドを$ scope変数にプッシュしていますが、この結果をバインドしていません。私のコードで何が間違っていますか?提案してください。機能配列がスコープ内にプッシュされている場合、ng-repeatは更新されません

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をevertimeこのWebメソッドを呼び出し、変数$スコープにそれらの結果を推進している:ここで

    <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> 

は結果である は、ここに私のコード

[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ですjsonの enter image description here

+0

あなたは、コールバック関数の実行されていますか?たとえば、デバッガを置く場所。 console.logに$ scope.StockListの内容を調べてみてください。 –

+0

どこでこの 'GetStockEntries'関数が呼び出されていますか?これはサービスメソッドのように見えますが、サービスは '$ scope'にアクセスできません。コントローラーでこれは? – Claies

+0

@ErikSvedin $ scope.StockList内にプッシュされている配列の番号を正確に返していません – Miranda

答えて

1

i gue ssの問題はあなたとng - repeat.tryいくつかのような場合は、いくつかの事が両方の項目で似ている場合は、条件をチェックします。

<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%"> 

とちょうど若干の変更:

= "stockItem.ProductID == sTockProduct.ProductID" データ-NG-IF

を行い、あなたの内側のテーブルには次のようにする必要がありますあなたの成功の中で:

$scope.result = obj; 

$scope.result = obj.data; 
関連する問題