[英]angular/ionic ng-click not updating the view, however it is updated in the model
[英]Angular view not updating properly on ng-click
我正在编写选择按钮菜单,当我尝试进入下一个选择级别时,什么也没有发生。
在第一个列表项中,我要写入下一个级别的选定值,在第二个列表项中,我成功列出了第一个级别的所有项,在第三个列表项中,我要显示第二个(最后一个)选项。
我的代码如下:
<div ng-if="selected.type=='number' && selected.values[0].values">
<ul class="smsUl">
<li ng-if="selected.selected">
<button class="btn btn-warning btn-block">{{selected.selected}}</button>
</li>
<li ng-repeat="value in selected.values" ng-if="attributes == undefined">
<button class="btn btn-info btn-block" ng-click="$parent.attributes=value.values">{{value.value}}</button>
</li>
<li ng-repeat="attribut in attributes" ng-if="attributes != undefined">
<button class="btn btn-info btn-block" ng-click="selected.value=attribut.id; selected.selected=attribut.value; attributes=undefined">{{attribut.value}}</button>
</li>
</ul>
</div>
一部分具有selected.values的jason看起来像:
[
{
"value": "clothing_glasses",
"values": [
{
"id": 1,
"value": "coat"
},
{
"id": 2,
"value": "glasses"
}
]
},
{
"value": "book_stationery",
"values": [
{
"id": 3,
"value": "book"
},
{
"id": 4,
"value": "document"
}
]
}
]
在nf-if表达式中,我尝试使用:
!attributes
但没有任何改变。
如果我在控制器中静态设置属性变量,它将列出我想要的内容,但是如果我选择,我应该回到1.级别。
您确定您未在控制器中执行以下操作:
$scope.attributes = [someArray]
(bla bla, some code)
$scope.someOnClickFunction = function() {
$scope.attributes = [otherArray]
}
如果是这样,那么您就失去了正确变量的范围,并且angular不再监视您认为应该的值。
我建议创建一些称为例如的对象。 “可观察”,将所有这些“属性”,“选定”等放置在那里,然后添加到您的控制器中:
$scope.$watchCollection('observable.attributes', function() {});
$scope.$watchCollection('observable.selected', function() {});
当您想更改这些数组中的某些内容时,请不要替换它们(通过将新数组应用于旧变量)。 如果您不想使用pushgin,shifting,poping元素,可以随时使用:
someDefinedArray.length = 0;
for-loop {
someDefinedArray.push(yoursobjects); //push objects back to array but with changes you wanted to make to array
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.