【发布时间】:2017-12-28 10:27:52
【问题描述】:
我正在尝试根据函数调用的结果有条件地向元素添加一个类,但 Aurelia 不会在其参数更改时重新运行该函数。通常我会使用 getter 来强制进行脏检查,但因为我的函数需要不可能的参数。
有问题的函数如下所示:
isVisible (item, filters) {
// If there are no filters selected, or at least one of the item's tag names are inside the filters the item is considered visible
return (!filters.length || (filters.length && item.tags.some(tag => {
return filters.indexOf(tag.name) !== -1 ? true : false;
})));
}
如果不是很明显,它需要一个 item 和一个字符串数组 (filters),然后检查 item.tags[].name 是否在 filters 数组内。
在我看来是这样使用的:
<item repeat.for="item of items" item.bind="item" class="${isVisible(item, filters) ? 'show' : 'hide'}"></item>
我还尝试将代码直接添加到视图中,我认为这会强制 Aurelia 重新计算事物,但是当将函数的全部代码添加到视图中时(在 ${code here} 内),我收到意外的解析错误 @ 987654329@.
【问题讨论】:
标签: aurelia