0
  1. 如何向“保存”事件发送完整的对象,包括用户在该行中输入的内容?目前,无论我做什么,这两个字段始终为 NULL。

  2. (临时评论)我把这个放在哪里?我想在单击“保存”时获取项目数据,但是如果我把它放在那里,我如何引用特定的行?

我开始的示例使用单独的页面进行列表/编辑,所以我遇到的问题是如何将功能组合到一个页面中。

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

1 回答 1

3

看起来它在 ng-repeat 中,因此控制器中的范围与 ng-repeat 中的范围不同。

我认为您可以从 items 中发送当前的 msa 元素,然后在 save 方法中,遍历与发送的元素匹配的原始列表,然后更新字段。

<button ng-click="save(msa)" class="btn btn-primary">
于 2013-08-23T17:02:08.850 回答