Is it possible to create a new reference to an array without going through the array?
(是否可以不通过数组就创建对数组的新引用?)
My problem is that I have a pure angular pipe which doesn't detect push/pop changes.(我的问题是我有一个纯角管,无法检测到推/弹出变化。)
I would like to avoid solutions like this:(我想避免这样的解决方案:)
this.array = this.array.filter(e=>true)
Which adds complexity just to update reference.
(只是为了更新参考而增加了复杂性。)
I have tried first thing that came to my head but it doesn't work (pipe doesn't detect any changes) and I am not familiar with js/ts enough to know why it didn't work.(我已经尝试过第一件事,但它不起作用(管道无法检测到任何更改),而且我对js / ts的熟悉程度不足以知道为什么它不起作用。)
const newRef = this.array;
this.array = null;
this.array = newRef
I have pipe which gets array of objects and array of filters and returns array of filtered objects.
(我有管道,它获取对象数组和过滤器数组并返回过滤对象的数组。)
@Pipe({
name: 'eventFilter'
})
export class EventFilterPipe implements PipeTransform {
transform(events: EventDtos[], filters:Filter[]): any {
//return filtered events
}
Pipe useage:
(管道用途:)
<div class="event" *ngFor="let event of events | eventFilter:filters">
html stuff
</div>
After pushing/poping filter from filters
, pipe's transform isn't called so I am using this code to force transform
call:
(从filters
推送/弹出过滤filters
,未调用管道的转换,因此我使用以下代码强制进行transform
调用:)
this.filters = this.filters.filter(e=>true)
But at this point I don't know which one is faster, this method or impure pipe.
(但是目前我不知道哪种方法更快,这种方法还是不纯管道。)
So Ideally I would like to leave pure pipe and update filters
reference without adding complexity(因此,理想情况下,我想保留纯管道并更新filters
参考,而不增加复杂性)
ask by askstackoverflow translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…