English 中文(简体)
4. 未启动的模式活动
原标题:Backbone.js model event not triggering

我查阅以下观点文件:

var BucketTransferView = Backbone.View.extend(
{
initialize: function(args)
{
    _.bindAll(this);
    this.from_bucket = args.from_bucket;
    this.to_bucket = args.to_bucket;
},
events:
{
     click input[type="submit"]  :  handleSubmit ,
},
render: function()
{
    $(this.el).html(ich.template_transfer_bucket(this.model.toJSON()));
    return this;
},
handleSubmit: function(e)
{
    that = this;

    this.model.save(
        {
            date: 1234567890,
            amount: this.$( #amount ).val(),
            from_bucket_id: this.from_bucket.get( id ),
            to_bucket_id: this.to_bucket.get( id )
        },
        {
            success: function()
            {
                // recalculate all bucket balances
                window.app.model.buckets.trigger(
                     refresh ,
                    [that.to_bucket.get( id ), that.from_bucket.get( id )]
                );
            }
        }
    );
    $.colorbox.close();
}
});

My buckets collection has this refresh method:

refresh: function(buckets)
{
    that = this;
    _.each(buckets, function(bucket)
    {
        that.get(bucket).fetch();
    });
}

我的问题是,如果真的发生并改变收集模式,则不会引发具有相同模式的其他观点类别的变化。 这些观点的模型与<代码>cid相同,因此,我认为这将触发。

发生这种情况的原因是什么?

最佳回答

Fetch将产生新的模型目标。 与收集工作挂钩的任何观点都应与收集活动挂钩,并重新招标。 观点模式仍然有相同的含义,因为它们重新提到了模式的旧版本。 如果看<代码>buckets的收集,则可能有不同的酸.。

我的建议是,让孩子们 the,你们应该让所有的儿童发表意见,并始终提及这些意见。 然后是重新开始活动,消除所有儿童的意见并重新提出。

initialize: function()
{
    this.collection.bind( reset , this.render);
    this._childViews = [];
},

render: function()
{
    _(this._childViews).each(function(viewToRemove){
        view.remove();
    }, this);

    this.collection.each(function(model){
        var childView = new ChildView({
            model: model
        });
        this._childViews.push(childView);
    }, this)
}

我希望,这有利于你们,或者至少使你们走上正确的方向。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签