Javascript 无法读取属性';isArray';未定义的
我正在使用主干网和yeoman的requirejs构建一个应用程序 我正在使用twitter的typeaheadjs,并随机得到这个错误!大多数情况下它都能工作,但有时typeahead即使不抛出任何错误也无法工作!而且在构建之后,typeahead甚至不起作用(grunt)。这是我称为typeahead的页面Javascript 无法读取属性';isArray';未定义的,javascript,requirejs,yeoman,typeahead.js,Javascript,Requirejs,Yeoman,Typeahead.js,我正在使用主干网和yeoman的requirejs构建一个应用程序 我正在使用twitter的typeaheadjs,并随机得到这个错误!大多数情况下它都能工作,但有时typeahead即使不抛出任何错误也无法工作!而且在构建之后,typeahead甚至不起作用(grunt)。这是我称为typeahead的页面 define([ 'jquery', 'underscore', 'backbone', 'templates', ... 'typeah
define([
'jquery',
'underscore',
'backbone',
'templates',
...
'typeahead',
...
], function ( $, _, Backbone, JST, a, b, typeahead, c, d) {
在这里,我初始化了视图的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 repoTypeahead不兼容AMD,您需要为它定义配置。可能是这样的:
requirejs.config({
// ...
shim: {
"typeahead": {
deps: ['jquery'],
exports: 'jQuery.fn.typeahead'
}
}
});
define(['jquery', 'typeahead'], function ($, youCanIgnoreThis) {
var opts = {
// ...
};
$("#SearchProduct").typeahead(opts);
})
阅读了解更多详细信息。这在开发版本中有效!现在开发版本工作得很好,但是在构建之后,typeahead就不工作了。这没有足够的信息来帮助您。我怀疑这可能是一个单独的问题,需要再问一个问题。