我已經查看了與此問題相關的所有信息(確定..第一次谷歌頁面點擊),但解決方案無法正常工作。jquery,bootstrap 3.0和requirejs。無法使用引導程序的功能
我config.js看起來象下面這樣:
var config = {
paths : {
jquery : "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min",
// "jquery" : "momsplanner/backgrid/assets/js/jquery",
"underscore" : "momsplanner/underscore/underscore",
"text" : "momsplanner/requirejs_text/text",
// "backbone" : "momsplanner/backbone",
"Backbone" : "momsplanner/backgird/assets/js/backbone",
"Backgrid" : "momsplanner/backgrid/lib/backgrid",
"bootstrap" : "momsplanner/bootstrap/dist/js/bootstrap"
// "bootstrap" : "//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap"
// 'jquery.bootstrap' : "momsplanner/backgrid/assets/js/bootstrap"
},
// A lot of dependencies don't support AMD loaders. Here is an example shim
// configuration to remedy that.
shim : {
"underscore": {
exports: '_'
},
"Backbone" : {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
"Backgrid" : {
deps: ['jquery', 'underscore', 'backbone'],
exports: 'Backgrid'
},
'bootstrap' : {
deps: ["jquery"]
}
}
};
if (typeof exports === 'object') {
// If this file is loaded from node, export the config variable.
module.exports = config;
} else if (typeof define === 'function' && define.amd) {
// If this file is being loaded in the browser, load the config
define([], function() {
requirejs.config(config);
});
}
而且我加載一個模塊就像下面
require([
'momsplanner/js/custom_bootstrap'
], function(custom_bootstrap) {
$(document).ready(function() {
custom_bootstrap.setNavbarActive();
custom_bootstrap.gotoTab();
});
});
custom_bootstrap樣子:
define([
"jquery",
"bootstrap"
], function($) {
.. omitting some functions..
// http://stackoverflow.com/questions/7862233/twitter-bootstrap-tabs-go-to-specific-tab-on-page-reload
function gotoTab() {
// Javascript to enable link to tab
var hash = document.location.hash;
var prefix = "tab_";
if (hash) {
var $selector = $('.nav-tabs a[href='+hash.replace(prefix,"")+']');
console.log($selector.html());
$selector.tab('show'); // ERROR HERE!!!! <------------------------
}
// Change hash for page-reload
$('.nav-tabs a').on('shown', function (e) {
window.location.hash = e.target.hash.replace("#", "#" + prefix);
});
}
return {
setNavbarActive: setNavbarActive,
gotoTab: gotoTab
};
我遇到錯誤信息在$ selector.tab('show')處顯示錯誤消息:
Uncaught TypeError: Object [object Object] has no method 'tab'
我該如何解決這個錯誤?
在你的其他帖子上看到我的回答:http://stackoverflow.com/a/19580457/2917432 – redmallard