【问题标题】:Elements missing in ng-repeatng-repeat 中缺少的元素
【发布时间】:2015-05-22 14:30:25
【问题描述】:

假设我在 HTML 中有这个

<div ng-repeat="tag in response.Tags | filter : searchKey">
</div>

我还有一个带有searchKey 模型的文本输入。

<input type="text" ng-model="searchKey">

response.Tags 是一个 JSON 数组。

现在的问题是,默认加载时,ng-repeat 填充的 UI 中缺少一些对象。当我使用文本输入并过滤列表时,我可以看到丢失的东西。

出了什么问题?

注意 - 数组没有变化。元素在那里。一旦加载它就不会改变。

编辑 这是我收到的原始数据。最多可包含 500 个元素,只有少数元素时不会遗漏任何内容。

    {
"AlertCategoryID": 15,
"AlertName": "Disk Space Low",
"AlertType": "Warning",
"AlertMessage": "<data><summary>Available disk space (%) on drive _Total is less than 10%. Current value is 5%.</summary><detail></detail></data>",
"AlertTime": "2015-05-21T19:24:03"
    }, {
"AlertCategoryID": 15,
"AlertName": "Disk Space Low",
"AlertType": "Warning",
"AlertMessage": "<data><summary>Available disk space (%) on drive _Total is less than 10%. Current value is 5%.</summary><detail></detail></data>",
"AlertTime": "2015-05-21T19:22:05"
}

我使用 XML 解析器来提取 &lt;summary&gt; 标记,我还截取并删除了日期和时间之间的 T;并将这些分配给我将用于 ng-repeat 的数组。

我在 UI 中显示 AlertName、Message 和它的时间。

我注意到倾向于丢失的元素在消息标记中有一个非常大的 XML。我不知道这是否与任何事情有关。

【问题讨论】:

  • 你的ng-modelsearchQuery,而不是searchKey
  • 抱歉这里打错了。
  • 不要在这里输入代码,总是复制/粘贴
  • 您能否举一个response.Tags 的示例以及初始加载时最终丢失的内容?更好的是 Plunker 示例
  • 感谢您的建议。不会再做了。

标签: javascript html angularjs angularjs-ng-repeat ng-repeat


【解决方案1】:

如果您想根据 JSON 对象中的特定键进行过滤,请使用以下语法

<div ng-repeat="tag in response.Tags | filter:{ AlertName: searchKey }">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 2017-09-14
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多