本文介绍了对收集的模型射击骨干事件(二次烧成)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个骨干应用程序有一个集合和一个模型,并为每个项目的相关意见。

A Backbone app which I'm developing has a collection and a model, and associated views for each item.

当我点击后览,不料,在集合的事件触发不受任何线路。

When I click on the PostView, unexpectedly, the event fires on the collection without any wiring.

我想我需要一个事件绑定到模型,然后让那场大火对收集的事件。是不是这样的?并集合自动地继承事件发射它的子模式?

I figured I'd need to bind an event to the model, then have that fire an event on the collection. Is that not the case? Does a collection automagically inherit events fired its child models?

我不确定,但是我认为它是与嵌套的意见,也许事件被两个地方,而不仅仅是内部约束

I'm uncertain, but I think it has something to do with the nested views, and maybe the event is being bound on both places instead of just the inner el.

推荐答案

从:

这是触发集合中的一个模型中的任何事件也将被收集直接触发,方便。

所以,是的,集监听事件对旗下所有车型,并转发。

So yes, the collection listens to events on all of its models and forwards them.

例如,给出一个简单的设置是这样的:

For example, given a simple set up like this:

class M extends Backbone.Model

class C extends Backbone.Collection
    model: M

c = new C
c.on('change', (model, opts) -> console.log('Change on collection'))

c.first()。集(...)将触发事件处理程序。

演示:

这篇关于对收集的模型射击骨干事件(二次烧成)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 07:53