我正在尝试将jQuery插件绑定到RequireJS
https://github.com/devbridge/jQuery-Autocomplete

require.config({
    paths: {
        "autocomplete":'./vendor/devbridge-autocomplete/dist/jquery.autocomplete'
    }

     shim: {
    "autocomplete": {
        deps: ['jquery']
    },
  }
)}


那我叫它,但这似乎没有用

 require(["jquery"], function($) {
$('.autocomplete').autocomplete({
        lookup: countries,
        onSelect: function (suggestion) {
            alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
        }
    });
})


提前致谢 !

最佳答案

由于Autocomplete已在使用AMD,并且需要jquery作为模块,因此必须对其进行定义。该配置将如下所示:

require.config({
    baseUrl: '/libs',
    paths: {
        jquery: 'jquery-1.9',
        autocomplete: 'jquery.autocomplete'
    },
     shim: {
        "autocomplete": ['jquery']
    },
});

关于javascript - 如何将devbridge/jQuery-Autocomplete插件与RequireJS关联?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29097194/

10-12 15:37