【发布时间】:2016-06-01 18:35:38
【问题描述】:
我有一个 ng-repeat 迭代对象,如:
{
"id": 1,
"title": "Lorem Ipsum",
"base_text": "Lorem ispum",
"read_more_text": "lorem ipsum",
"show_details": false,
"button_label": "Read More",
"button_link": "",
"image": ""
},
在 html 的 ng-repeat 内,有一个按钮,我想切换 show_details 属性的值。
所以,我有一个ng-click 处理程序:
<div class="hero-item" ng-repeat="h in dash.heroItems">
<div>
<h3>{{h.title}}</h3>
<p>{{h.base_text}}</p>
<p ng-if="h.show_details">{{h.read_more_text}}</p>
</div>
<div>
<button ng-click="dash.showHeroDetails(h.id)">{{h.button_label}}</button>
</div>
</div>
所以我传递了重复实例的ID 属性。但是在这里我被卡住了,我无法获得切换该布尔属性的正确语法。
到目前为止我有这个:
_this.showHeroDetails = function (item) {
_this.show_details = item;
};
这显然是错误的......
【问题讨论】:
-
如果你能用更多代码构建一个工作的 plunker,那将非常有帮助。
标签: javascript angularjs json angularjs-ng-repeat