[英]JavaScript Object.Observe delegation
I have JavaScript array which is consists of many objects. 我有由许多对象组成的JavaScript数组。
var array=[{name:1},{name:2}.....]
I want to use Object.observe
to handle data changes on each of these objects. 我想使用
Object.observe
处理每个这些对象上的数据更改。
Is there any way to apply something like event delegation here , in order to not apply observe
for each of objects? 为了不对每个对象应用
observe
,有什么方法可以在这里应用事件委托之类的东西?
If I use Object.observe
for array itself than changing its items doesn't trigger anything. 如果我将
Object.observe
用于数组本身,则更改其项不会触发任何操作。
No, that's not possible. 不,那不可能。
Imagine code like this: 试想这样的代码:
var foo = {...};
var bar = [foo, {..}, {..}, {..}]
Object.yourWeirdMagicObserve(bar, ..);
Would changing foo
trigger your callback now? 更改
foo
触发您的回调? Or only modifications to bar[0]
? 还是仅对
bar[0]
进行修改? When you use bar[0]
the object is retrieved from bar
but besides that it has no association with bar
whatsoever. 当您使用
bar[0]
,将从bar
检索对象,但除此之外,它与bar
没有任何关联。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.