gpt4 book ai didi

javascript - 在 AngularJs 中传递变量值作为过滤器参数

转载 作者:行者123 更新时间:2023-11-30 09:47:58 25 4
gpt4 key购买 nike

是否可以在 AngularJs 中将变量值作为过滤器参数传递?

假设我有一些帖子,每个帖子都有一个标签 ID 数组。我有 allTags 集合(id、标签),我想在帖子后显示标签标签。

<ul ng-repeat="post in posts">
{{post.title}}
{{post.body}}
<li ng-repeat="allTags|myFilter:post.tagIds">

allTags: [{5:'tagfive'}, {1:'one'}, {3:'myTag'}]
posts[0]: {title:'my post', tagIds:[3,5], body:' post body'}

:是否有可能传递一个变量值(在我的例子中是一个数组)到一个过滤器

最佳答案

Is it possible to pass a variable value (in my case an array) to a filter

是的。对于过滤器函数中使用的每个参数:

app.filter(function(){
return function(array, param1, param2){
return .... // filter logic
})
});

您使用 : 来表示 html 中的参数

<li ng-repeat="allTags|myFilter:post.tagIds :scopeProp1: scopeProp2">

引用:filter docs

关于javascript - 在 AngularJs 中传递变量值作为过滤器参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37980263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com