无法更改范围属性

时间:2019-01-22 15:02:55

标签: javascript angularjs angularjs-scope

im试图将属性值更改为angular js的$ scope变量,但尚未设置应用的更改。

我的代码是这样的:

在我的代码中,我有一个costBudget,其中有许多子项放入数组中,我需要将这些子项重新放置到costWorkPackages数组中。

let costBudget = $scope.list[0];
costBudget.subCostsWorkPackages = costsWorkPackages;
console.log(costBudget);

costBudget变量在分配新数组之前和之后是相同的,但是它是错误的。我希望costBudget有新孩子,但不会发生。

已更新: 添加的控制台对象:

更改前:

{code: 1, internalId: 0, notRealWorkPackage: true, name: "shrh", 
count: 1, …}
$$hashKey: "object:190"
code: 1
subCostsWorkPackages: Array(3)
0: Resource {id: 6491, name: "ascasca", count: 1,         
subCostsWorkPackages: Array(0), resourceInstances: Array(0), …}
1: Resource {id: 6492, name: "ascasca", count: 1, 
subCostsWorkPackages: Array(0), resourceInstances: Array(0), …}
2: Resource {id: 6493, name: "ascasca", count: 1, 
subCostsWorkPackages: Array(0), resourceInstances: Array(0), …}
$promise: Promise {$$state: {…}}
$resolved: true
length: 3
__proto__: Array(0)
 subNodeClass: ""
title: "shrh"
toggleButtonClass: "fa-minus-square-o"
__proto__: Object

之后:

{code: 1, internalId: 0, notRealWorkPackage: true, name: "shrh", 
count: 1, …}
$$hashKey: "object:190"
code: 1
subCostsWorkPackages: Array(3)
0: Resource {id: 6491, name: "ascasca", count: 1, subCostsWorkPackages: Array(0), resourceInstances: Array(0), …}
1: Resource {id: 6492, name: "ascasca", count: 1, subCostsWorkPackages: Array(0), resourceInstances: Array(0), …}
2: Resource {id: 6493, name: "ascasca", count: 1, subCostsWorkPackages: Array(0), resourceInstances: Array(0), …}
$promise: Promise {$$state: {…}}
$resolved: true
length: 3
__proto__: Array(0)
subNodeClass: ""
title: "shrh"
toggleButtonClass: "fa-minus-square-o"
__proto__: Object

更新2:

控制台中的

costsWorkPackage变量:

[Resource, Resource, Resource, Resource, $promise: Promise, $resolved: 
true]
0: Resource {id: 6430, name: "Nombre 2", count: "1.00000000", 
subCostsWorkPackages: Array(0), resourceInstances: Array(0), …}
1: Resource {id: 6437, name: "Nombre 9", count: "1.00000000", 
subCostsWorkPackages: Array(0), resourceInstances: Array(0), …}
2: Resource {id: 6438, name: "Nombre 3", count: "1.00000000", 
subCostsWorkPackages: Array(5), resourceInstances: Array(2), …}
3: Resource {id: 6431, name: "Nombre 3", count: "1.00000000", 
subCostsWorkPackages: Array(5), resourceInstances: Array(2), …}
$promise: Promise {$$state: {…}}
$resolved: true
length: 4
__proto__: Array(0)

0 个答案:

没有答案