我在使用canJS和stealjs时遇到了问题,我克隆了javascriptmvc的回购(3.3使用canJS)。现在我有了这个文件夹结构
/js
/can
/documentjs
/funcunit
/plugins
.
.
.在我的应用程序的另一部分中,我有一个“独立模块”布局(使用脚手架工具生成)。我在我的页面中使用"js/steal/steal.js?path/to/module/layout“加载这个模块,它可以工作。如果我在layout.js中偷了一些jquery插件(例如位于主js文件夹中),如下所示:
steal('plugins/jqueryplugin.js', 'plugins/jqueryplugin.css', function() {
// my code here
});它仍然可以工作,但是当我试图在"canJS“中添加一些组件(即使是使用tool...because生成的fixture.js )时,它就会停止工作,破坏一切。我也尝试过使用:
steal('that').then('this', function() {});但我有同样的results.....fail!有什么线索吗?
发布于 2013-04-30 09:05:40
好的,我发现了问题。stealjs和canjs没有什么问题,但是
canjs只是加载它自己版本的jquery。
那会破坏我的申请。现在,我需要找到一种分别加载canjs和jquery的方法(我使用yii,有些扩展需要在特定的时间加载jquery,因此不能等待jquery)。
发布于 2013-05-01 14:48:52
问题是jQuery的版本还是依赖关系的顺序?
您可以通过stealconfig.js配置the,以使用另一个版本的jQuery并管理任何依赖项。
在github中可以找到一个示例:(这个示例没有显示依赖项,因此我在下面添加了一个) https://github.com/bitovi/steal/blob/master/stealconfig.js
steal.config({
map: {
"*": {
"jquery/jquery.js": "jquery", // Map to path
"bootstrap/bootstrap.js": "bootstrap",
"can/util/util.js": "can/util/jquery/jquery.js"
}
},
paths: {
"jquery": "can/lib/jquery.1.8.3.js", // Path to jQuery
"bootstrap": "lib/bootstrap.js"
"yui/yui.js" : "can/lib/yui-3.7.3.js",
},
shim : {
jquery: {
exports: "jQuery"
},
bootstrap: { // A dependency example
'deps': ['jquery']
}
},
ext: {
js: "js",
css: "css",
less: "steal/less/less.js",
coffee: "steal/coffee/coffee.js",
ejs: "can/view/ejs/ejs.js",
mustache: "can/view/mustache/mustache.js"
}
});注:这是一个未经测试的例子,希望这会有所帮助。
发布于 2014-06-23 10:02:09
我对偷来的东西也有意见,我知道它对JavascriptMVC很有效,
现在,我使用AMD需求it来管理依赖关系,这对canjs非常有用。这是文档http://canjs.com/guides/using-require.html,希望它能对你有所帮助!
https://stackoverflow.com/questions/16292267
复制相似问题