如何将devbridge / jQuery-Autocomplete插件与RequireJS联系起来?

时间:2015-03-17 10:51:04

标签: javascript jquery requirejs shim

我正在尝试将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);
        }
    });
}) 

提前感谢!

1 个答案:

答案 0 :(得分:1)

由于自动完成已经使用AMD并且需要jquery作为模块,因此您必须对其进行定义。配置看起来像这样:

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