简体   繁体   English

使用ng-click和ng-repeat创建过滤器菜单

[英]Using ng-click with ng-repeat to create a filter menu

I'm trying to use ng-repeat to create my filter menu, with all the modalities inside my timeline. 我正在尝试使用ng-repeat来创建我的过滤器菜单,并在时间轴内包含所有模式。

<a ng-click="filterModality = {entry_team.name: '{{modality}}'}" ng-repeat="modality in modalities">{{modality}}</a>

<!-- 
Output 
<a ng-click="filterModality = {entry_team.name: 'Atletismo'}" ng-repeat="modality in modalities">Atletismo</a>
-->


<a ng-click="filterModality = {entry_team.name: 'Atletismo'}">Atletismo</a>

The ng-repeat doesn't work but the same output doing manually worked fine. ng-repeat不起作用,但是手动执行相同的输出效果很好。 I'm using AngularJS 1.2.9 (unfortunately). 我正在使用AngularJS 1.2.9(不幸的是)。

It looks like you're mixing interpolation with two-way binding. 看起来您正在将插值与双向绑定混合在一起。 Also, you are setting an object reference in the ng-repeat scope which is probably creating a new object reference in that scope which then masks the reference of the same name in the parent scope. 另外,您要在ng-repeat范围中设置对象引用,这可能会在该范围中创建一个新的对象引用,然后在父范围中屏蔽相同名称的引用。

Try defining your object in the parent scope using filterModality = {} and then just change the property value in the ng-click instead of changing the object reference. 尝试使用filterModality = {}在父范围内定义对象,然后在ng-click中更改属性值,而不是更改对象引用。

<a ng-click="filterModality['entry_team.name'] = modality" ng-repeat="modality in modalities">{{modality}}</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM