过滤器:angularjs 中的 notarray 错误

编程入门 行业动态 更新时间:2024-10-28 06:28:15
本文介绍了过滤器:angularjs 中的 notarray 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

http://plnkr.co/edit/cJsScs8ixF1aq85Ri7nV?p=preview

过滤器不起作用.代码的其他部分也中断了.抛出错误过滤器:notarray.如何修复它

<link rel="stylesheet" href="style.css"><body ng-init="items=[3,1,2,3];"><h1>你好,Plunker!</h1><div >

<input type="text" ng-model="nm"/><div ng-repeat="item in items track by $index | filter:nm" ng-hide="hide">{{物品}}

<button ng-click="hide=!hide">切换 </button><button ng-click="items[items.length]=items.length">添加</button><script src="https://code.angularjs/1.4.2/angular.min.js"></script><script src="script.js"></script></html>

解决方案

ng-repeat 说:

<块引用>

track by 必须始终是最后一个表达式

所以你需要改变这一行:

到此:

我知道这很晦涩难懂,而这个很容易让人认出.文档通常不在您期望的页面上(例如过滤器),但仍位于合乎逻辑的位置(例如 ng-repeat).它应该"都在那里.

http://plnkr.co/edit/cJsScs8ixF1aq85Ri7nV?p=preview

filter is not working. Other part of code also breaks. Throwing error filter:notarray. how it can be fixed

<head>
  <link rel="stylesheet" href="style.css">

</head>

<body ng-init="items=[3,1,2,3];">
  <h1>Hello Plunker!</h1>

  <div >

  </div>
  <input type="text" ng-model="nm" />



  <div ng-repeat="item in items track by $index | filter:nm" ng-hide="hide">
    {{item}}

  </div>

  <button ng-click="hide=!hide">Toggle </button>
  <button ng-click="items[items.length]=items.length">Add</button>


  <script src="https://code.angularjs/1.4.2/angular.min.js"></script>
  <script src="script.js"></script>
</body>

</html>

解决方案

The documentation for ng-repeat says:

track by must always be the last expression

So you need to change this line:

<div ng-repeat="item in items track by $index | filter:nm" ng-hide="hide">

to this:

<div ng-repeat="item in items | filter: nm track by $index" ng-hide="hide">

I know it's obscure, and this one catches people out. Often the documentation isn't on the page you expect it to be (e.g. filter) but is still in a logical place (e.g. ng-repeat). It 'should' all be there.

这篇关于过滤器:angularjs 中的 notarray 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 19:40:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1008931.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   错误   angularjs   notarray

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!