我在将select2添加到早午餐配置时遇到问题。我正在使用带有早午餐的phoenix框架1.3。我认为是与jQuery有关的问题,但我不知道是什么原因引起的。我检查了早午餐没有两次加载jQuery。
对于像下面这样的简单呼叫,它会抛出TypeError: undefined is not a function (near '...$('.select2-tags').select2...')
$('.select2-tags').select2({
ajax: {
url: API.tagSearchUrl(),
dataType: 'json'
}
});
这是我的早午餐配置。
exports.config = {
files: {
javascripts: {
joinTo: {
"js/app.js": /^js/,
"js/vendor.js": /^(?!js)/
}
},
stylesheets: {
joinTo: {
"css/app.css": /^css/,
"css/vendor.css": /^(?!css)/
},
order: {
after: ["priv/static/css/app.scss"]
}
},
templates: {
joinTo: "js/app.js"
}
},
conventions: {
assets: /^(static)/
},
paths: {
watched: ["static", "css", "js", "vendor", "scss", "fonts"],
public: "../priv/static"
},
// Configure your plugins
plugins: {
babel: {
ignore: [/vendor/]
},
sass: {
options: {
includePaths: [
"node_modules/bootstrap/scss",
"node_modules/font-awesome/scss",
],
precision: 8
}
},
copycat: {
"fonts": ["node_modules/font-awesome/fonts"] // copy node_modules/font-awesome/fonts/* to priv/static/fonts/
}
},
modules: {
autoRequire: {
"js/app.js": ["js/app"]
}
},
npm: {
enabled: true,
whitelist: ["phoenix", "phoenix_html"],
globals: {
$: 'jquery',
Popper: 'popper.js',
bootstrap: 'bootstrap',
_: 'underscore',
alertifyjs: 'alertifyjs',
Dropzone: 'dropzone',
select2: 'select2' // version 4.0.5
},
styles: {
alertifyjs: ["build/css/alertify.min.css", "build/css/themes/default.min.css"],
dropzone: ["dist/min/dropzone.min.css"]
}
}
};
哦,天哪,我想我解释了我的问题,但是由于代码与文本的比率,堆栈溢出不容忍发布。