简体   繁体   English

如何在angularjs中更新数组的元素?

[英]How to update the elements of array in angularjs?

I want to replace the Item of an array to the newly created item here is the function 我想将数组的项目替换为新创建的项目,这里是函数

 $scope.getPageDetails = function () {
        $http.get('/api/privilege/getpagedetails/')
            .success(function (data, status) {
                $scope.Pages = data;
                angular.forEach($scope.Pages, function (value, key) {
                    var url = "//" + (value.pageUrl);

                    console.log(url);
                    $scope.Pages.pageUrl = url;
                });
                $scope.$applyAsync();

            }).error(function () {
            });
    }

I got the value of pageUrl from array $scope.Pages[] which is recoveryguidance.com then I added // on the pageUrl var url = "//" + (value.pageUrl); 我从数组$ scope.Pages []获得了pageUrl的值, 数组是recoveryguidance.com,然后在pageUrl上添加了// // var url = "//" + (value.pageUrl); then it becomes //recoveryguidance.com then how can I push the updated value on array $scope.pages[] in the place of pageUrl. 然后变成//recoveryguidance.com,然后如何将更新后的值推送到数组$ scope.pages []上的pageUrl处。 In short I want to update value from recoveryguidance.com to //recoveryguidance.com of pageUrl column in $scope.pages array. 简而言之,我想将$ scope.pages数组中的值从recoveryguidance.com更新到//recoveryguidance.com pageUrl列。

I am attaching the data also I want to update pageUrl recoveryguidance.com to //recoveryguidance.com. 我还要附加数据,我也想将pageUrl recoveryguidance.com更新到//recoveryguidance.com。

在此处输入图片说明 ageUrl ageUrl

Please guide me I will be very thankful to you all. 请指导我,我将非常感谢大家。

Try this: 尝试这个:

angular.forEach($scope.Pages, function (value, key) {
    value.pageUrl = "//" + (value.pageUrl);
});

JSFiddle 的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM