使用括号表示法添加到关联数组时,ng-repeat 不会更新
ng-repeat does not update when adding to an associative array using bracket notation
我是 Angular 的新手,我正在尝试将项目添加/推送到关联数组中。但是,当我使用括号表示法时,ng-repeat中的数据不会更新。我不知道为什么。
在 JS/coffee 控制器文件中,我有这个:
$scope.openDoc = (contentNumber)->
$scope.openDocs[contentNumber] = {"content":"This is content"}
在HTML/Jade文件中,我有这个:
li(ng-repeat="(number, doc) in openDocs")
a.(data-toggle="tab", ng-href="{{'#'+number}}") {{number}}
和这个(当用户单击此行时,它成功触发 openDoc 函数):
tr(ng-repeat="(number, doc) in otherDocs", ng-click="openDoc(number)")
我觉得自己太愚蠢了。由于尝试在 jsfiddle 中重新创建它,我现在有了答案。这是我的原始代码:
http://jsfiddle.net/Ey9nQ/3/
我最初的问题是我从一个空对象开始:
$scope.things =[];
当我在控制台.log中输出它时,这显示得很好,但是在角度下不起作用。我需要将其更改为:
$scope.things = {};
这是工作版本:http://jsfiddle.net/Ey9nQ/4/
相关文章:
- 如何从 Angular ng-repeat 指令中检索数组中的某些索引
- ng-repeat不绑定ng-model对象数组
- AngularJS:如何使用ng repeat来显示父数组中包含的数组的所有元素
- 使用ng repeat用数组中的数据填充表行
- 使用括号表示法添加到关联数组时,ng-repeat 不会更新
- AngularJS - 如何访问嵌套ng-repeat中的数组
- 替换 ng-repeat 数组会导致奇怪的重新渲染
- 如何使用 ng-repeat $index 在数组中查找元素
- 如何在 ng-repeat 中按键分配对象数组
- AngularJs:我想从数组或列表中添加一个类,用于ng-repeat中的每次迭代
- 如何将 ng-repeat 中的范围变量传递给 JavaScript 数组
- 复选框列表 将数组格式化为 JSON 并在 ng-repeat 中映射后未填充
- Angular js 监视带有 ng-repeat 的 Select 标签上的对象数组
- 如何在 AngularJS ng-repeat中对 Json 数组值求和
- 双向绑定 ng-repeat 中的字符串数组
- 在 ng-repeat 中验证数组名称属性
- 动态更新数组 ng 重复
- Angular2多维数组ng-for不能工作
- 使用数组ng-model
- Angular:如何在锚标签数组(ng-repeat)中禁用锚标签