Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng对键值对象重复自定义筛选器仅更新视图2次_Javascript_Angularjs_Google Chrome Extension_Angularjs Ng Repeat_Angularjs Filter - Fatal编程技术网

Javascript ng对键值对象重复自定义筛选器仅更新视图2次

Javascript ng对键值对象重复自定义筛选器仅更新视图2次,javascript,angularjs,google-chrome-extension,angularjs-ng-repeat,angularjs-filter,Javascript,Angularjs,Google Chrome Extension,Angularjs Ng Repeat,Angularjs Filter,我创建了一个自定义过滤器,用于过滤键/值对,例如: module.controller('tabController', ['$scope', function ($scope) { var self = this; self.items = { "a": "a", "b": "b", "c": "c" } 过滤器: module.filter('filterKeyValue', function () { return func

我创建了一个自定义过滤器,用于过滤键/值对,例如:

module.controller('tabController', ['$scope', function ($scope) {
   var self = this;
   self.items =  {
       "a": "a",
       "b": "b",
       "c": "c"
   }
过滤器:

module.filter('filterKeyValue', function () {

return function (items, input) {
    if (!input) return items;
    input = input.toLowerCase();

    let filtered = {};
    let reverse = false;
    if (input.startsWith('!')) {
        input = input.slice(1).trim();
        reverse = true;
    }

    angular.forEach(items, (value, key) => {
        let k = key.toLowerCase();
        let v = value.toLowerCase();
        let indexOfKey = k.indexOf(input);
        let indexOfValue = v.indexOf(input);

        if (!reverse) {
            if (indexOfKey >= 0 || indexOfValue >= 0) {
                filtered[key] = value;
            }
        } else {
            if (indexOfKey < 0 && indexOfValue < 0) {
                filtered[key] = value;
            }
        }
    });
    console.log('filtered items: ', filtered);
    return filtered;
};
});
我使用以下标记(简短版本):


钥匙
价值
{{key}}
{{value}}
这对我来说是没有意义的,它在前两次起作用,之后就不再起作用了


这里可能有什么问题?此代码在chrome扩展(popup.html)中运行,但我认为这不重要。

我找到了解决此问题的方法:

在我的场景中,这个问题是由于我原型化了“对象”造成的。
我没有在过滤器中使用原型。但是仅仅是在代码中的某个地方就导致了这个问题…

我找到了这个问题的解决方案:

在我的场景中,这个问题是由于我原型化了“对象”造成的。
我没有在过滤器中使用原型。但是,仅仅是在代码中的某个地方就导致了这个问题……

你有什么问题吗。它在这里起作用@Rhea我看到它确实起作用了。这让我把我的整个应用程序都删掉了。我认为这是由于第三方图书馆。我得弄清楚是哪一把你有小提琴吗。它在这里起作用@Rhea我看到它确实起作用了。这让我把我的整个应用程序都删掉了。我认为这是由于第三方图书馆。我需要弄清楚是哪一个。。
So i search for:
'a' -> works fine, view gets updated ('a' exists in 'items')
'b' -> works fine, view gets updated ('b' exists in 'items')
'c' -> does not work, the view does not get updated ('c' exists in 'items')
'f' -> does work, view gets updated with no results ('f' does NOT exist in 'items')
<div ng-controller="tabController as tab">

 <input type="text" ng-model="tab.filter">

 <table>
   <thead>
        <tr>
           <th>Key</th>
           <th>Value</th>
        </tr>        
   </thead>
   <tbody>
      <tr ng-repeat="(key,value) in tab.items | filterKeyValue:tab.filter">
        <td>{{key}}</td>                                
        <td>{{value}}</td>
      </tr>
   </tbody>
</table>

</div>