gpt4 book ai didi

javascript - Angular.js 从 ng 重复更新对象数据

转载 作者:行者123 更新时间:2023-12-03 07:25:12 25 4
gpt4 key购买 nike

我的应用程序中有两个页面,一个显示事物列表,第二个显示该列表中的单个项目。我已经构建了一个函数,该函数通过调用服务器端 api 来更新状态,然后返回修改后的项目,现在我怎样才能使我的 View 更新为新项目?我现在想在项目详细信息页面上更新我的列表中的状态吗?显而易见

我这样调用该函数:

 ... href="#" ng-click="change_status(i.item_id,2)">In Text</div>

在我的 Controller 中:

 $scope.change_status = function (id, sts) {
MySrv.changeStatus(
{ item_id: id, item_sts: sts, user_id: window.UD.user_id
})
.then(function (response) {
//I am getting back my object here ->How can i now
//update the view for this specific object?
});
}

最佳答案

您还可以使用一些简短的方法来仅替换当前对象。您需要在 change_status 函数中传递该对象的当前索引,成功后,您需要使用 splice 替换该对象功能类似于 -

$scope.change_status = function (id, sts , index) {
MySrv.changeStatus(
{ item_id: id, item_sts: sts, user_id: window.UD.user_id
})
.then(function (response) {
yourObjectList.splice(index,1,response);
});
}

关于javascript - Angular.js 从 ng 重复更新对象数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36029853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com