假设我在 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 解析器提取 <summary>
标签,我也拦截并删除了日期和时间之间的 T;并将它们分配给我将用于 ng-repeat 的数组。
我在 UI 中显示警报名称、消息及其时间。
我注意到容易丢失的元素在消息标记中有一个非常大的 XML。我不知道这是否与任何事情有关。
最佳答案
如果要根据 JSON 对象中的特定键进行过滤,请使用以下语法
<div ng-repeat="tag in response.Tags | filter:{ AlertName: searchKey }">
关于javascript - ng-repeat 中缺少的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30389337/