gpt4 book ai didi

javascript - 无法读取未定义的属性 'isArray'

转载 作者:行者123 更新时间:2023-12-02 18:17:24 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com