Javascript 将jQuery UI对话框与Backbone.js和RequireJS一起使用
我想做我的第一个网页,使用骨干弹出窗口Javascript 将jQuery UI对话框与Backbone.js和RequireJS一起使用,javascript,jquery,jquery-ui,backbone.js,requirejs,Javascript,Jquery,Jquery Ui,Backbone.js,Requirejs,我想做我的第一个网页,使用骨干弹出窗口 define(['jquery', 'jqueryui', 'underscore', 'backbone', 'api', 'text!' + versions.getVersionedPath('templates/form.html') function ($, jqueryui, _, Backbone, Api, Form) { var widok = Backbone.View.extend({ formularz:
define(['jquery',
'jqueryui',
'underscore',
'backbone',
'api',
'text!' + versions.getVersionedPath('templates/form.html')
function ($, jqueryui, _, Backbone, Api, Form) {
var widok = Backbone.View.extend({
formularz: _.template(Form),
el: 'body',
events: {
'click #test': 'test',
'click .del': 'usun',
'click #elo': 'test2'
},
initialize: function () {
this.$el.html(this.formularz());
self = this;
console.log('This model has been initialized.');
this.render();
},
render: function () {
console.log('Showing up');
this.$el.html(this.formularz());
},
test: function () {
self.showNews();
return false;
},
test2: function () {
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Delete all items": function () {
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
}
});
return {initialize: function () {
console.log('Initialize');
new widok;
self.showNews();
console.log('blablablablabla');
}};
});
我有这样的函数,但当我试图使用它时,我有如下错误
Uncaught TypeError: $(...).dialog is not a function.
我已经定义了jquery和jqueryui。有人能帮我吗
把它放在requirejs配置上
shim: {
jqueryui: {
"deps": ['jquery']
},
您共享的代码有语法错误,您没有关闭依赖项数组 jQuery用户界面支持版本为
1.11.0
的AMD。这里有一个与AMD装载机一起使用的示例
因此,如果您使用的是最新版本,请从配置中删除垫片
还要注意,模块中的jqueryui
将是未定义的
,因为它不导出任何内容,所以最好在依赖项末尾添加这样的内容,如:
define([
'jquery',
'underscore',
'backbone',
'api',
'text!' + versions.getVersionedPath('templates/form.html'),
'jqueryui'],
function ($, _, Backbone, Api, Form) {});
您是否为jQueryUI定义了垫片?请发布requirejs配置。是的,我已经为jQueryUI定义了垫片:)jQueryUI并没有真正导出任何内容,所以最好将其添加为最后一个。也许这条路错了什么的?顺便问一下,您使用的是什么版本的jQuery UI?我使用的是2.1.1version@nEJVI没有这样的事吗?最新版本类似于~1.11.0
。。?