【问题标题】:assigning id to new added object in ngrepeat将 id 分配给 ngrepeat 中新添加的对象
【发布时间】:2015-10-30 11:42:59
【问题描述】:

我正在使用 Xeditable Angular,

工作正常。

问题是当我将新数据作为新行添加到表时。我对服务器进行了 ajax 调用,服务器保存了它,并返回了新的 id,我想将此 id 分配给新添加的模型。我是怎么做到的。

当我添加一个新项目时,它通过 xeditable 立即添加到模型中,它很好,但它的 id 字段为空,我想将空更改为服务器的返回值。如何通过 id 选择最后编辑的项目

    <tr ng-cloak ng-repeat="school in results = (content.data  | filter: content.search | orderBy:sortType:sortReverse | offset: (content.currentPage-1) * content.pageSize | limitTo: content.pageSize) track by school.id">
      <td><input type="checkbox" ng-model="content.deleteList[school.id]" ng-checked="content.head"></td><td>{{school.id}}</td> .......................................

仅显示部分

【问题讨论】:

    标签: angularjs x-editable


    【解决方案1】:

    您可以做的是在收到服务器回复时更新 id:

    $scope.addData = function(user) {
        yourFactory.addData(user).then(function(result) {
            user.id = result.data.id;
        });
    }
    

    如果您提供更多代码,我可能会更好地帮助您

    【讨论】:

    • @lggy 我正在使用 angular xeditable 添加数据,我正在使用添加行方法,只有两个选项,onaftersave 和 onbeforesave,我认为这不起作用,我会尝试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 2015-11-05
    • 2020-09-20
    • 2019-11-27
    • 1970-01-01
    相关资源
    最近更新 更多