gpt4 book ai didi

backbone.js - Stackmob 与 requires.js

转载 作者:行者123 更新时间:2023-12-02 22:38:20 25 4
gpt4 key购买 nike

我正在布置基本结构并开始创建模型。问题是模型中丢失了对初始化 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 对象?

最佳答案

引入 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;
});

主.js

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

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

模型.js

(使用 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;
});

关于backbone.js - Stackmob 与 requires.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11113636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com