[英]Get editable row of data from angular and sending it to WEB api
如何将完整的对象(包括用户在该行中键入的内容)发送到“保存”事件? 现在,无论我做什么,这两个字段始终为NULL。
(临时评论)我该放在哪里? 我想在单击“保存”时获取项目数据,但是如果我将其放入其中,如何引用特定行?
我开始的示例使用单独的页面进行列表/编辑,因此我遇到的问题是如何将功能组合到一个页面中。
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>
看起来好像是在ng-repeat中,所以控制器中的作用域与ng-repeat中的作用域不同。
我认为您可以只发送项目中的当前msa元素,然后在save方法中循环遍历与所发送元素匹配的原始列表,然后更新字段。
<button ng-click="save(msa)" class="btn btn-primary">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.