我在一个Backbone
项目中使用browserify
,并填充owlCarousel,因为它不是一个类似commonJS
的模块。shim
转换似乎可以工作,但在我真正需要它的时候却不行。
我的app.js
文件看起来像:
var settingsView = require("./settingsView.js");
new settingsView();
和我的settingsView
var app = require("./controllers.js"),
$ = require("jQuery"),
Backbone = require("Backbone"),
owlCarousel = require("owlCarousel");
Backbone.$ = $;
module.exports = Backbone.View.extend({
el: ".settings",
events: {
"click .carousel-img": "setBackground",
"click .palette div": "setTextColor"
},
options: {
singleItem: true,
pagination: false,
navigation: true,
mouseDrag: false
},
initialize: function () {
this.initCarousel();
},
initCarousel: function () {
/* This is causing the problem */
this.owlCarousel = this.$el.find(".carousel").owlCarousel(this.options);
}
})
我的package.json
"browser": {
"jquery": "./node_modules/jquery/dist/jquery.js",
"owlCarousel": "./vendor/owl-carousel/owl-carousel/owl.carousel.js"
},
"browserify": {
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"jquery": "$",
"owlCarousel": {
"depends": ["jquery:$"]
}
}
它给我的错误是:
未捕获的类型错误:这个.$el.find(...).owlCarousel不是函数
但是,如果我在dom就绪后在控制台中运行$("div").owlCarousel
,它就可以工作了。
1条答案
按热度按时间ma8fv8wu1#
我解决了做