0
我想加載一個叫做fancytree的jQuery控件,這個控件取決於jquery-ui。我得到一個錯誤,說它沒有從我給出的路徑加載jquery-ui。 Fancytree也依賴另一個名爲fancytree.table的文件。加載jquery-ui在require.js配置fancytree插件
我的目錄結構是這樣的
js
/app
....
/lib
/jquery
/underscore
/backbone
/vendor
/jquery-ui
/fancytree
錯誤:
jquery.js:2 Uncaught Error: Fancytree assertion failed: Fancytree requires jQuery UI (http://jqueryui.com)(…)
配置:
require.config({
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
paths: {
'jquery': '../lib/jquery/jquery',
'underscore': '../lib/underscore/underscore',
'backbone': '../lib/backbone/backbone',
'text': '../lib/text/text',
'jquery-ui': '../vendor/jquery-ui/jquery-ui',
'fancytree': [
'../vendor/fancytree/fancytree',
'../vendor/fancytree/fancytree.table'
],
},
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
},
'jquery-ui': {
exports: "$",
deps: ['jquery']
},
},
baseUrl: '/js/app',
});
觀點:
define(['jquery-ui', 'fancytree', 'require'], function(ui, fancytree, require){
'use strict';
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
tpl = require('text!templates/categories.html'),
template = _.template(tpl);
return Backbone.View.extend({
el: $('#tree'),
initialize: function() {
this.listenTo(this.collection, 'reset add change remove', this.render, this);
this.collection.fetch();
},
initFancyTree: function() {
console.log('tree');
$('#fancytree').fancytree();
},
render: function() {
this.$el.html(template());
//this.initFancyTree();
return this;
}
});
})
嘿thnks爲您提供幫助,但我得到另一個錯誤處理正在加載到視圖的模板錯誤是:未捕獲的錯誤:模塊名稱「text!templates/categories.html_unnormalized2」尚未加載對於上下文 – ONYX
這是關於text.js文件 – ONYX
@ONYX這是另一個問題,與此線程無關。試着自己調試一下,如果一切都失敗了,請回過頭來問問。 –