我正在布局基本结构,并开始创建模型。问题是在模型中丢失了对初始化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对象可供模型模块访问?
答案 0 :(得分:5)
介绍StackMob的种实例?
define(['stackmob'], function(StackMob) {
StackMob.init({
appName: {appName},
clientSubdomain: {clientSubdomain},
apiVersion: 0
});
// return a particular StackMob that we've initialised
return StackMob;
});
(根据您的示例代码,似乎不再使用StackMob)
require(['modernizr','jquery','backbone', 'underscore', 'routers/router'], function(Modernizr, $, Backbone, _, Router) {
// Instantiates a new Router
this.router = new Router();
});
(使用my-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;
});