【发布时间】:2013-08-29 18:22:39
【问题描述】:
我有一个自定义数据类型Message:
function Message(body, author, date) {
this.body = body;
this.author = author;
this.date = date;
this.stars = [];
}
Message.prototype.hasStars = function() {
return this.stars.length !== 0;
};
我也在重复这些消息的数组:
<li ng-repeat='message in messages | orderBy:"-stars.length"'>…</li>
如何向其添加调用message.hasStars() 的过滤器?我尝试了以下方法,但都没有效果:
message in messages | filter:message.hasStars() | orderBy:"-stars.length"
message in messages | filter:message:hasStars() | orderBy:"-stars.length"
message in messages | filter:message.hasStars | orderBy:"-stars.length"
message in messages | filter:message:hasStars | orderBy:"-stars.length"
【问题讨论】:
-
你需要一个自定义过滤器
-
@sza 这不是真的。请参阅“Jared 之类的词”的答案。
-
@jessegavin 这不过是一个过滤器。您可以使用
filter模块或仅使用函数来创建过滤器。 -
它是一个谓词函数,但它没有通过依赖注入器以角度注册为“过滤器”。
标签: javascript angularjs