假设我有一个(相当可笑的)书籍模型,其属性看起来像:
page:{
paragraph:{
wordcount: {
the: 8,
at: 10
}
}
}
我可以像这样绑定(bind)到非常嵌套的值的更改吗?
book.on("change:page:paragraph:wordcount:the", ...);
最佳答案
Backbone 只触发顶级属性名称的 change
事件。根据 Catalog of Events :
- "change" (model, options) — when a model's attributes have changed.
- "change:[attribute]" (model, value, options) — when a specific attribute has been updated.
那里没有提到任何嵌套。事实上,如果您确实更改了属性的嵌套属性,我很确定它甚至不会触发事件(因为属性本身没有更改)。此外,如果您查看带注释的来源(尽管影响此行为的因素有些分散),您可以将其跟踪到 where change:attribute
events are triggered。 .
但是,它看起来确实像there's a plugin帮助完成您的追求。
关于javascript - 我可以将主干更改事件嵌套多深?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10402796/