English 中文(简体)
通行证收集。 fetch, as apoint function to Collection. 工作约束
原标题:Passing collection.fetch as a named function to collection.bind does not work

我有两套备用藏书。 我想对重启事件负责。 当这次事件发生时,我要提一下第二次收缴行动,例如:

App.collections.movies.bind("reset", App.collections.theaters.fetch);

第二只字不提火。 然而,如果我通过匿名职能,打电话给殴打者。 fetch, 它没有问题:

App.collections.movies.bind("reset", function () { App.collections.theaters.fetch(); });

为什么会发生这种情况?

这里,我的全面法典。 我不想展示任何模式或收集,因为它有许多法典,但请允许我知道,你是否认为这个问题的根源:

var App = {

    init: function () {
        App.collections.theaters = new App.Theaters();
        App.collections.movies = new App.Movies();

        App.events.bind();
        App.events.fetch();

    },

    events: {
        bind: function () {
            App.collections.theaters.bind("reset", App.theaterManager.assign);

            App.collections.movies.bind("reset", function () { App.collections.theaters.fetch(); });
        },

        fetch: function () {
            App.collections.movies.fetch();
        }
    },

    collections: {},

    views: {},

    theaterManager: {

        // Provide each model that requires theaters with the right data
        assign: function () {
            // Get all theaters associated with each theater
            App.theaterManager.addToCollection("theaters");

            // Get all theaters associated with each movie
            App.theaterManager.addToCollection("movies");
        },

        // Add theaters to a collection
        addToCollection: function (collection) {
            App.collections[collection].each(function (item) {
                item.theaters = App.theaterManager.getTheaters(item.get(("theaters")));
            });
        },

        // Returns a collection of Theaters models based on a list of ids
        getTheaters: function () {
            var args;

            if (!arguments) {
                return [];
            }

            if (_.isArray(arguments[0])) {
                args = arguments[0];
            } else {
                args = Array.prototype.slice.call(arguments);
            }

            return new App.Theaters(_.map(args, function (id) {
                return App.collections.theaters.get(id);
            }));
        }
    }
};

$(function () {
    App.init();
});
问题回答

所有这一切都与职能环境有关。 这与在 Java稿中要求职能的方式有着共同的混淆。

我首先要说的是,你正在履行一项职责,但没有界定任何背景。 这意味着,无论谁打电话,都将成为“这”。 等值很可能是打电话App. Collections.movies.fetch(),这不是你想要的。 至少,我猜想的是,情况如何。 难于知道......它可能是 j,可能是<条码>Backbone.sync。 唯一的出路是在<条码>Backbone. Collections.fetch功能中添加一个断点,并打印出<条码>的。 不管怎么说,它胜出的就是你们想要的。

在第二种情况下,你将它交给另一个职能,但在内部,你具体说明了要求履行这一职能的背景。 在此情况下,fetch就座标有App. Collections.theaters

......这是明确的?





相关问题
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.

热门标签