我正在使用 Backbone 、requirejs 和 yeoman 构建一个应用程序。
我使用 Twitter 的 typeaheadjs 并随机收到此错误!大多数时候它可以工作,但有时提前输入甚至不会抛出任何错误!并且在构建之后,预输入甚至无法工作(咕噜声)这是我调用预输入的页面
define([
'jquery',
'underscore',
'backbone',
'templates',
...
'typeahead',
...
], function ( $, _, Backbone, JST, a, b, typeahead, c, d) {
这是我初始化 View render() 内的 Typeahead 的地方
this.collection.fetch({
success: function (data) {
$('#SerachProduct').typeahead({
name: 'abc',
valueKey: 'name',
local: data.toJSON(),
template: JST['app/scripts/templates/typeahead.ejs']
});
},
error: fun() {..
}
}
这是 github 存储库 Github
最佳答案
Typeahead 与 AMD 不兼容,您需要定义 shim对其进行配置。它会是这样的:
requirejs.config({
// ...
shim: {
"typeahead": {
deps: ['jquery'],
exports: 'jQuery.fn.typeahead'
}
}
});
define(['jquery', 'typeahead'], function ($, youCanIgnoreThis) {
var opts = {
// ...
};
$("#SearchProduct").typeahead(opts);
})
阅读the documentation了解更多详情。
关于javascript - 无法读取未定义的属性 'isArray',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19163156/