国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - The value obtained when looping in angular is the last value
天蓬老師
天蓬老師 2017-07-05 11:05:07
0
2
942

code show as below:

angular.forEach(data.body.data.assets,function(val,ind){

                    angular.forEach(val.userAssetList,function(data,index){
                        val.userDtoName = data;
                        // alert(data.userDTO);
                        if(val.assetCount != val.availableCount){
                            lay.push(val);
                        }
                    })
                   })
          最后我的lay數(shù)組中userDtoName的值全部都是最后一個data的值。為什么。但是每一個循環(huán)中alert出來的是不同的。
天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進(jìn)步~~

reply all(2)
曾經(jīng)蠟筆沒有小新

val is an object, equivalent to a pointer, so the same object is pushed in every time

Since I don’t know what other attributes and functions your val has, here is only an alternative: push({...val, userDtoName: data})

Using ES6’s... spread operator.

洪濤

If you read it correctly, what you use conveniently is val.userAssetList, but you put val into lay. It’s the same every time, and you always execute lay.push(val)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template