林试图怎么办
林推对象到一个数组,这样按预期工作。但是,当我尝试通过他们的父母$,$指数和$索引更新数组中的一个对象的所有对象进行更新。
对象被推入阵列(多次)
// Array for Objects
$scope.arr = []
// Object to be pushed into Array
$scope.obj = {
content:[
{
type:"text",
data:"This is Dummy Text",
style:{
"height":"500px"
}
},
// Could be more than one Object within Content
]
}
上述目的将被推入$ scope.arr多次,对象被环的视图内。
// Looped Arrays
<div ng-repeat="l1 in arr track by $index">
<div ng-repeat="l2 in l1.content" ng-style="l1.style">{{l1.data}}</div>
</div>
更新由$父。$指数和$指数
所以在这一点我已在$ scope.obj多次被推到$ scope.arr而这正是问题的发生。
我需要通过这样一行代码的更新只有$ scope.obj的在$ scope.arr下列操作之一:
// Set $index's to target the specific array items
var parentIndex = 0
var index = 0
$scope.arr[parentIndex].content[index].style['height']
可能的更新的一个例子是以下几点:
var o = parseInt($scope.arr[parentIndex].content[index].style['height'])
var n = o + 1
$scope.arr[parentIndex].content[index].style['height'] = new + 'px'
目前,上述将更新所有插入/推入$ scope.arr对象,尽管设置正确的$父。$指数和$指数。我需要针对并更新一个,而不是全部。
我必须在这里失去了一些东西,任何帮助或指导是极大的赞赏。
能否请你重新读一遍你的阙并改正它?你指的对象和数组,但它看起来像任你混合一些事情,或者你不想想他们在传统的方式。 {}是一个对象,[]是一个数组。不管你如何调用变量(虽然它可以帮助你连续调用它们) – Gavriel
“new”是一个关键词,它不能用于你的变量名。 – Gavriel
@Gavriel我刚刚纠正它。变量“新”只是作为一个例子,但这是很好的知道。 – HireLee