2016-02-25 53 views
0

錯誤:TypeError:$(...)。selectpicker不是函數第一次打開Web應用程序時發生的錯誤。

在我app.js

 
requirejs.config({ 
    baseUrl: '', 
    paths: { 
     "jquery": "js/jquery", 
     "jquery-ui": "js/jquery-ui", 
     text: "lib/text", 
     //"css": "css", 
     handlebars: 'js/handlebars', 
     moment: "js/moment.min", 
     bootstrap: 'js/bootstrap.min', 
     somtjquery: 'widgets/somt/js/somtjquery', 
     bootstrapselect: 'js/bootstrap-select', 
     utils: 'widgets/somt/js/utils', 
     filterwidget: 'widgets/somt/js/filterwidget' 
    }, 
    shim: { 
     handlebars: { 
      exports: 'Handlebars' 
     }, 
     'bootstrap': { 
      deps: ['jquery'] 
     }, 
     //'bootstrapdatepicker':{deps: ['jquery','bootstrap']}, 
     'somtjquery': { 
      deps: ['jquery', 'utils', 'bootstrap'] 
     }, 
     'bootstrapselect': { 
      deps: ['jquery', 'bootstrap'] 
     }, 
     'jquery': { 
      exports: '$' 
     }, 
     "datepicker": { 
      deps: ["jquery-ui", "bootstrap"], 
      exports: "$.fn.datepicker" 
     }, 
     'tooltip': { 
      deps: ['jquery'], 
      exports: '$.fn.tooltip' 
     }, 
     'filterwidget': { 
      deps: ['jquery', "jquery-ui", "bootstrap", "bootstrapselect"], 
      exports: 'filterwidget' 
     } 
    } 
}); 

In filterwidget.js 

define(["handlebars",'hbs!widgets/somt/templates/pfilter'],function(Handlebars,filter){ 
    var selector = "#somt-filter-area"; 
    $(selector).html(filter); 
    $(function selectDatePicker() { 
     try { 
      $(selector).find('.selectpicker').selectpicker(); 
     } catch (e) { 
      console.log("Date select err message : " + e); 
     } 
     try { 
      $(selector).find("#week").datepicker({ 
       showOn: "button", 
       buttonImage: "images/common-calendar-month-glyph.svg", 
       buttonImageOnly: true, 
       firstDay: 1, 
       beforeShowDay: function(date) { 
        return [date.getDay() === weekofday, ""]; 
       }, 
       dayNamesMin: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], 
       maxDate: currentcutoffday, 
       dateFormat: 'mm/dd/yy' 
      }); 
     } catch (e) { 
      console.log("Date picker err message : " + e); 
     } 
    }); 
}); 

特別是我在Firefox 36及以下版本

回答

0

你誤會了如何使用shim得到了錯誤。配置沒有filterwidget的正確依賴關係。使用'shim'必須只適用於非amd庫。如果文件有define功能比它的amd模塊和shim對該模塊沒有必要。從shim刪除此代碼:

'filterwidget': { 
     deps: ['jquery', "jquery-ui", "bootstrap", "bootstrapselect"], 
     exports: 'filterwidget' 
    } 

和設置filterwidget所有依賴於filterwidget.js:

define(['jquery', "jquery-ui", "bootstrap","bootstrapselect","handlebars",'hbs!widgets/somt/templates/pfilter']

PS:也墊片刪除了jQuery,jQuery的UI。這是AMD的庫。你怎麼知道?看看圖書館的開始。例如'jquery-ui'。如果有這樣的事情:

if (typeof define === "function" && define.amd) { 

    // AMD. Register as an anonymous module. 
    define([ "jquery" ], factory); 
} else { 

    // Browser globals 
    factory(jQuery); 
} 

然後墊片是不需要的。

相關問題