Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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 如何在Angularjs中创建过滤器?_Javascript_Angularjs_Data Binding_Angularjs Filter - Fatal编程技术网

Javascript 如何在Angularjs中创建过滤器?

Javascript 如何在Angularjs中创建过滤器?,javascript,angularjs,data-binding,angularjs-filter,Javascript,Angularjs,Data Binding,Angularjs Filter,我有以下课程: [{ id: 1, courseId: 2, text: 'John' }, { id: 2, courseId: 2, text: 'Willi' }, { id: 3, courseId: 2, text: 'Inga' }, { id: 4, courseId: 1, text: 'Jerry' }, { id: 5, courseId: 1, text: 'Michael' }, { id: 1, courseId: 3, text: 'John'

我有以下课程:

 [{ id: 1, courseId: 2, text: 'John' },
  { id: 2, courseId: 2, text: 'Willi' },
  { id: 3, courseId: 2, text: 'Inga' },
  { id: 4, courseId: 1, text: 'Jerry' },
  { id: 5, courseId: 1, text: 'Michael' },
  { id: 1, courseId: 3, text: 'John' },
  { id: 2, courseId: 3, text: 'Willi' },
  { id: 3, courseId: 4, text: 'Inga' },
  { id: 4, courseId: 5, text: 'Jerry' },
  { id: 5, courseId: 5, text: 'Michael' }]
我有一个id数组:

[{"id": 3},{"id": 2},{"id": 1}] 
我需要按id'si.e的数组过滤课程数组,以便仅显示courseId=3,2,1的文本课程:

ng-repeat="course in courses| customFilter: [{"id": 3},{"id": 2},{"id": 1}]"
我需要在angularJS中创建自定义过滤器,该过滤器将按id数组过滤课程数组


您知道如何实现自定义过滤器吗?

您可以创建自定义过滤器,以便为您提供过滤值,过滤器应将元素数组作为过滤器数组

加价

滤器


您可以创建自定义过滤器,以便为您提供过滤值,过滤器应将元素数组作为过滤器数组

加价

滤器


我在angularJs项目中创建了一个过滤器

在我的angularApp中,名称是angularApp

var app = angular.module('angularApp', []); // This is your main angular app.
现在您需要为解码url创建一个过滤器

上面的代码是创建一个过滤器来解码url。我的过滤器名是“decodeURL”。我们将在我的代码中使用decodeURL作为过滤器 就像你的URL是-

测试2 tes3

然后将URL设置为如下所示-

如何在html中使用此筛选器-

//以上是angularjs中的状态路由

//上面的URL重定向代码


我在angularJs项目中创建了一个过滤器

在我的angularApp中,名称是angularApp

var app = angular.module('angularApp', []); // This is your main angular app.
现在您需要为解码url创建一个过滤器

上面的代码是创建一个过滤器来解码url。我的过滤器名是“decodeURL”。我们将在我的代码中使用decodeURL作为过滤器 就像你的URL是-

测试2 tes3

然后将URL设置为如下所示-

如何在html中使用此筛选器-

//以上是angularjs中的状态路由

//上面的URL重定向代码


,我有这个格式筛选器:customFilter:[{id:3},{id:2},{id:1}]不是这个:customFilter:[3,2,1]为什么你需要这种过滤器为什么不简化它呢?因为我从服务中得到了这个结果。我需要把它保存在foramt中,尽管我做了相应的更改。一定要查看它们。谢谢你的帮助,但似乎有一些错误,我有这个格式的过滤器:customFilter:[{id:3},{id:2},{id:1}]不是这个:customFilter:[3,2,1]为什么需要这种过滤器?为什么不简化它?因为我从服务中得到了这个结果。尽管我做了相应的更改,但我需要保留它。请查看它们。谢谢您的帮助,但似乎有一些错误
var app = angular.module('angularApp', []); // This is your main angular app.
app.filter('decodeURL', function() {
    return function(text) {
        if(text) {
            return text.split(' ').join('-').toLowerCase().replace(/[^a-z0-9]+/g, '-');
        }
    }
});
<a ui-sref="{{business.category[0].categoryName.toLowerCase()}}Detail({id:business.id,title:(business.title | decodeURL)})"></a>
<a href="/coupon/{{coupon.id}}/{{coupon.title | decodeURL}}"
                                       class="btn btn-warning show-btnhome show-button-margin">Show</a>