- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在使用 UI-Select 0.8.4 并且有一个大数据集。然后我使用 UI-Select 在数据集旁边的下拉列表中显示属性值。我将其用于过滤器。因此,当从下拉列表中选择时,将过滤结果。
每次当我将鼠标悬停在下拉列表中的某个项目上时,它总是会触发 ng-repeat 过滤器。
这滞后于我的应用程序,因为我在 ng-repeat 中处理大量数据。
这是为什么?
动图: http://i.imgur.com/cStlXzy.gif
Plunker (打开控制台并亲自查看): http://plnkr.co/edit/OxiutZ8t4IX1bOxiOTgo?p=preview
HTML:
<h3>Age list</h3>
<p>Selected: {{age.selected}}</p>
<ui-select ng-model="age.selected" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select a person">{{$select.selected}}</ui-select-match>
<ui-select-choices repeat="age in ageArray | filter: $select.search">
<div ng-bind="age | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
JavaScript:
$scope.theFilter = function(item) {
console.log(item);
return item;
};
$scope.ageArray = [];
$scope.$watch('people', function(item) {
for(var i = 0; i < item.length; i++) {
$scope.ageArray.push(item[i].age);
}
});
$scope.people = [
{ name: 'Adam', email: 'adam@email.com', age: 10 },
{ name: 'Amalie', email: 'amalie@email.com', age: 12 },
{ name: 'Wladimir', email: 'wladimir@email.com', age: 30 },
{ name: 'Samantha', email: 'samantha@email.com', age: 31 },
{ name: 'Estefanía', email: 'estefanía@email.com', age: 16 },
{ name: 'Natasha', email: 'natasha@email.com', age: 54 },
{ name: 'Nicole', email: 'nicole@email.com', age: 43 },
{ name: 'Adrian', email: 'adrian@email.com', age: 21 }
];
编辑:我什至尝试从“数据集数组”中过滤出属性值并在下拉列表中使用它,但它不起作用。
编辑 2: 如果您认为 watch 触发了这个,我删除了 watch ,这仍然是一个问题:http://plnkr.co/edit/oD3Tt3vfjtOjADMnemW1?p=preview
编辑 3: 仍然没有找到解决方案,所以我坚持 chosen .我 created an issue但没有得到任何回应。 如果你想解决这个问题,请给这个问题投票。
最佳答案
问题是过滤器在每个 $digest
(每个 ng-mouseenter、ng-click 等)上执行。对于庞大的数据集,这显然会降低性能。 (参见本文 http://www.bennadel.com/blog/2489-how-often-do-filters-execute-in-angularjs.htm)
相反,尝试对 age.selected
值执行 $watch
,然后仅在该值实际发生变化时才应用过滤器。
http://plnkr.co/edit/TIeKPAyrAQsGHwakqwEp?p=preview
HTML
<!-- filtered list "ageMatches" -->
<ul ng-show="age.selected">
<li ng-repeat="person in ageMatches">{{person.name}} - {{person.age}}</li>
</ul>
<!-- default list of all "people" -->
<ul ng-hide="age.selected">
<li ng-repeat="person in people">{{person.name}} - {{person.age}}</li>
</ul>
JS
// add age to scope
$scope.age = {};
// add age match placeholder
$scope.ageMatches = [];
// watch age.selected for changes, apply filter
$scope.$watch('age.selected', function(newVal, oldVal){
if(newVal){
$scope.ageMatches = $filter('filter')($scope.people, {age: newVal});
}
});
关于javascript - ng-repeat 在悬停时连续发射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27234374/
我的代码 "> 我想做的是 如果外层 ng-repeat 中的 n 为 0,则 div.book_container 将如下所示: 否则,di
嗨,我有一个用于 ng-repeat-start 和 end 的简单用例,并且工作正常,当我想添加内部 ng-repeat 时出现问题。 这是我的代码 {{e}} {{obj.descr
我正在查看一长串 DNA 核苷酸,并正在寻找以起始代码“AAA”开头并以终止代码“CCC”结尾的序列。由于核苷酸以三联体形式出现,因此我找到的每个序列开始和结束之间的核苷酸数必须是三的倍数。 例如,'
我有这个: .... #{item.product.codigoProduto} #{m.description} ... listRequ
我从服务请求中返回了以下 json 数据: { "entries": [{ "id": 2081, "name": "BM", "niceNam
在 Aurelia 中嵌套 repeat.for 时,内部 repeat.for 无权访问其父 repeat.for 中使用的变量>. 示例 ${x} - ${y} 在上面的示
我有一个带有类别的对象,在这个对象内部有一个名为 items 的对象,其中包含带有 items 的对象。 现在我想重复显示这样的项目: {{cat
我有... html, body { background-size: contain; background-repeat: no-repeat; } 作为我的 CS
我的问题如下:旋转时,由重复图案组成的背景发生变化,因此图案被拉伸(stretch)而不是重复。可能有什么问题? 我有这个由重复图案组成的背景: 最佳答案 您必须手动设置重复模式: parent =
关于下面的元素 如何编辑 element.style?我想要 background-repeat : no-repeat; 不确定从哪里设置它。 element { display: blo
我有一个 Observable,我想定期重复,但仅限于以下条件: apiInterface.getData() // returns Observable ... // processing is h
我无法停止 td 元素中的图像重复。它看起来很难看。我该如何解决这个问题?我也添加了 background-repeat: no-repeat 代码,但它仍然无法正常工作。请不要建议从我的 td 宽度
我想知道以下哪个示例的效果更好。如果性能相同,哪个读起来更好? 示例 1(重复选择器) .helpfulCommenter, .questionTroll { 颜色:#f00; } .question
我正在尝试创建 tooltip对于通过 ng-repeat. 创建的表的第一行 但是工具提示没有呈现。 HTML $(document).ready(function () {
我正在开发一个页面,我需要在其中显示一些框(使用 ng-repeat ),其中包含 channel 信息以及显示位置(城市)。 我面临的问题是当我重复第二个 ng-repeat : 这应该获得第一个
我在另一个 ng-repeat 中有 ng-repeat,并且两者都有分页数据。 主要的工作正常,但 ng-repeat 内的分页数据并不总是工作。它会抛出控制台错误。 错误:[$interpolat
所以我有这个小问题。我对所有项目使用 ng-repeat,我们称它们为国家,每个项目本身都有一个 ng-repeat 作为城市等子类别。我用国家/地区填充下拉菜单。 所以我有这样的国家列表: 美国 德
我有一条从 Angular $resource promise 返回的记录,如下所示。 记录是一个数组,每个记录数组中都有另一个变量数组。我尝试在我的 View 中显示如下。 div(ng-repe
我需要使用 ng-repeat 来生成多个元素,但这些元素不能分别包装在 div 内(这是用于框布局的目的,其中框布局仅适用于直接子元素)。例如,我需要这个结果: Head 1 Body 1
我已经看到(很多)许多教程和装饰器的片段 w/和 w/o 参数,包括我认为是规范答案的两个:Decorators with arguments , python decorator arguments
我是一名优秀的程序员,十分优秀!