IOR*_*R88 5 angularjs angularjs-ng-repeat angularjs-ng-init
<input ng-model="search.name" placeholder="Name" />
<tbody>
<div ng-init="FilteredGeojson = ho|filter:search">
<tr ng-repeat="hf in FilteredGeojson">
<td>{{ hf.name }}</td>
</tr>
</div>
</tbody>
</table>
<div leaflet-directive id="map" data="FilteredGeojson"></div>
Run Code Online (Sandbox Code Playgroud)
如果可能的话,在ng-init中进行过滤是很重要的,但是我无法解决它,我无法进行ng-repeat和创建我传递给我的指令的范围,因为它启动了无限的摘要循环.
Sha*_*lav 14
您的代码段不起作用因为ho并且filter:search是不同的陈述.在
ng-init="FilteredGeojson = ho | filter:search"
Run Code Online (Sandbox Code Playgroud)
...分配FilteredGeojson = ho在| filter:search应用过滤器之前完成,但不起作用.
您需要封装过滤值,如下所示:
ng-init="FilteredGeojson = (ho | filter:search)"
Run Code Online (Sandbox Code Playgroud)
在ng-init中进行过滤非常重要
重要的是什么?ngInit指令只会在那里调用一次,因此当您更新过滤器时,ngRepeat不会更新项目.但你需要这个,对吗?
要实现这一点,您应该在ngRepeat指令中添加filter ,如下所示:
<tr ng-repeat="hf in FilteredGeojson | filter:search">
<td>{{ hf.name }}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7583 次 |
| 最近记录: |