2013-08-23 70 views
0
  1. 如何向「保存」事件發送完整對象,包括用戶在該行中輸入的內容?現在,無論我做什麼,這兩個字段總是空的。從角度獲取可編輯的數據行並將其發送到WEB api

  2. (the temp comment)我把這個放在哪裏?我想在單擊「保存」時獲取項目數據,但是如果我將它放在那裏,我該如何參考特定行?

我開始使用單獨的頁面進行列表/編輯的例子,所以我遇到的問題是如何將功能組合到一個頁面中。

var ListCtrl = function($scope, $location, Msa) { 
    $scope.items = Msa.query(); 

    //temp: since I do not know how to get the value for specific row 
    var id = 1; 
    $scope.msa = Msa.get({id: id}); 

    $scope.save = function() { 
     Msa.update({id: id}, $scope.msa, function() { 
      $location.path('/'); 
     }); 
    } 
}; 
<tbody> 
    <tr ng-repeat="msa in items"> 
     <td>{{msa.PlaceId}}</td> 
     <td>{{msa.Name}}</td> 
     <td> 
      <div class="controls"> 
       <input type="text" ng-model="msa.PreviousPlaceId" id="PreviousPlaceId"> 
      </div> 
     </td> 
     <td> 
      <div class="controls"> 
       <input type="text" ng-model="msa.NextPlaceId" id="NextPlaceId"> 
      </div> 
     </td> 
     <td> 
      <div class="form-actions"> 
       <button ng-click="save()" class="btn btn-primary"> 
        Update 
       </button><i class="icon-save"></i> 
      </div> 
     </td> 
    </tr> 
</tbody>  

回答

3

它看起來就像是在NG-重複這樣的範圍是不是在控制器中的一樣,在NG-重複。

我認爲你可以從項目中發送當前的msa元素,然後在保存方法中,通過匹配發送元素的原始列表循環,然後更新字段。

<button ng-click="save(msa)" class="btn btn-primary"> 
+0

另一種方式來引用,而不是通過它我可以使用this關鍵字是嗎? var id = this.msa.PlaceId; – punkouter

相關問題