2

我正在布置基本结构并刚刚开始创建模型。问题是对初始化 Stackmob 的引用在模型中丢失了。

main.js
require(['modernizr','jquery','backbone', 'underscore', 'routers/router', 'stackmob'], function(Modernizr, $, Backbone, _, Router, Stackmob) {

    StackMob.init({
        appName: {appName},
        clientSubdomain: {clientSubdomain},
        apiVersion: 0
    });

    // Instantiates a new Router
    this.router = new Router();
});

Model.js
define(['jquery', 'backbone', 'stackmob', 'models/business'], function($, Backbone, Stackmob, Business) {

    var BusinessesCollection = StackMob.Collection.extend({

            model: Business,

            // Model Constructor
            initialize: function() {

            }

    });

    // Returns the Model class
    return BusinessesCollection;

});

如何让模型模块可以访问已初始化的 StackMob 对象?

4

1 回答 1

5

介绍一种StackMob的实例?

我的-stackmob.js

define(['stackmob'], function(StackMob) {
    StackMob.init({
        appName: {appName},
        clientSubdomain: {clientSubdomain},
        apiVersion: 0
    });
    // return a particular StackMob that we've initialised
    return StackMob;
});

main.js

(根据您的示例代码,似乎不再直接使用 StackMob)

require(['modernizr','jquery','backbone', 'underscore', 'routers/router'], function(Modernizr, $, Backbone, _, Router) {
    // Instantiates a new Router
    this.router = new Router();
});

模型.js

(使用我的stackmob)

define(['jquery', 'backbone', 'my-stackmob', 'models/business'], function($, Backbone, Stackmob, Business) {
    var BusinessesCollection = StackMob.Collection.extend({

            model: Business,

            // Model Constructor
            initialize: function() {

            }

    });

    // Returns the Model class
    return BusinessesCollection;
});
于 2012-06-20T11:10:03.843 回答