避免使用全局变量和使用带有requirejs的Jquery ui

时间:2014-05-21 22:09:20

标签: jquery jquery-ui requirejs

我正在尝试使用requirejs jquery和jquery ui.want来避免全局变量$和jquery 我写了一个加载jquery ui的脚本

requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: '{!URLFOR($Resource.Prototype)}'+'/js',
    paths: {
        jquery : 'jquery-1.7.2.min',
        jqueryui : 'jquery-ui-1.10.4.custom.min',
        jquerymobile : 'jquery.mobile-1.4.2.min',
    jquerytouchpunch : 'jquery.ui.touch-punch'},
    map: {
      '*': { 'jquery': 'jquery-private' },
      'jquery-private': { 'jquery': 'jquery' }
    },
     shim: {
        'jqueryui': {
            exports: "$",
            deps: ['jquery']
        },
        'jquerytouchpunch' : {
        exports: "$",
        deps: ['jquery','jqueryui','jquerymobile']
        }


    }});

的jquery-private.js

define(['jquery'], function (jq) {
    return jq.noConflict( true );
});

我试图在我的模块中使用jqueryui

define(['jqueryui','ModuleData','DataFormatterUtility'],function($,ModuleData,d){
 return {  
  RetrieveAndAppendContacts : function(unlinkedContacts){
  var contactsHtml = "";
console.log('$ is');
  console.log($);
  $.each(unlinkedContacts,function(i,obj){
    contactsHtml += d.ContactDataFormatter(obj);
  });
   $(".contact-wrapper .inner").empty().append(contactsHtml);
 }
});

我在控制台中收到错误

Uncaught TypeError: Cannot read property 'ui' of undefined jquery-ui-1.10.4.custom.min.js:6
Uncaught TypeError: Cannot read property 'support' of undefined jquery.ui.touch-punch.js:14
$ is ContactModule.js:5
undefined 

任何人都可以在这种情况下解释如何使用jqueryui。谢谢:)

0 个答案:

没有答案