简体   繁体   English

使用数组的Aurelia值转换器

[英]Aurelia Value Converters using array

I have a question with Value Converters, I have an array w/c filters inactive item, when I am editing an item and change the status property to 'INACTV', the table does not change. 我对值转换器有疑问,我有一个带w / c过滤器的非活动项目数组,当我编辑项目并将status属性更改为“ INACTV”时,表不会更改。 but when adding/removing items in the array, it refreshes, my workaround is creating a binded _signal property to force the filtering, is there a way not to do this? 但是当在数组中添加/删除项目时,它会刷新,我的解决方法是创建一个绑定的_signal属性以强制进行过滤,有没有办法不这样做呢?

< tr repeat.for="item of ARRAY | filtercustom:'STATUS_CD':'INACTV':_signal" > <tr repeat.for =“阵列的项| filtercustom:'STATUS_CD':'INACTV':_ signal”>

I'm not sure I understood how the filter is supposed to work. 我不确定我是否了解过滤器的工作原理。 But if it should hide inactive items, maybe you could do something like 但是,如果它应该隐藏不活动的项目,也许您可​​以执行类似的操作

<tr repeat.for="item of ARRAY" if.bind="!item.STATUS_CD='INACTV'">

I don't know if it is possible to put a value converter inside a "repeat.for". 我不知道是否可以在“ repeat.for”中放入值转换器。 Looks weird. 看起来很奇怪。

I hope this helps to push you in the right direction. 我希望这有助于将您推向正确的方向。

No, there is no direct, clean way to do this at the moment. 不,目前没有直接,干净的方法可以执行此操作。 Repeat.for uses a CollectionObserver for array observation which only responds to pop/push/reverse/shift/sort/splice/unshift. Repeat.for使用CollectionObserver进行数组观察,它仅对pop / push / reverse / shift / sort / splice / unshift作出响应。

Only when one of these methods is called on the array, the observer fires and the array is fed to your ValueConverter again. 仅当在数组上调用这些方法之一时,观察者才会触发,并将数组再次馈送到ValueConverter

Your signal solution is about as clean as it gets. 您的信号解决方案将尽其所能。 It's more efficient than the alternative of refreshing the whole array from manually instantiated property observers on your STATUS_CD property on every item in the array. 它比从阵列中每个项目的STATUS_CD属性上的手动实例化属性观察器刷新整个阵列的替代方法更有效。 Which is what I do in some similar situations, because I don't like using signals. 在某些类似情况下,我会这样做,因为我不喜欢使用信号。 But that's just a matter of preference. 但这只是一个喜好问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM