我如何使用下面的脚本,其中jquery $ .fn.serializeObject()与require.js一起出现?
我收到以下错误:
未捕获的TypeError:无法读取未定义的serializeObject.js的属性'fn': (匿名函数)
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
这是我的视图保存功能,提供错误:
var participantDetails = $(ev.currentTarget).serializeObject();
是否需要一些我错过的其他依赖?
这是我的main.js:
require.config({
shim: {
"jquery": {
exports: '$'
},
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone',
init: function (_, $) { Backbone.$ = $; return Backbone; }
},
backbone_tastypie: {
deps: ['backbone', 'underscore', 'jquery'],
attach: "Backbone"
},
serialize: {
deps: ['jquery']
//exports: 'jQuery.fn.serializeObject'
}
},
paths: {
jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min',
underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min',
backbone: '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min',
backbone_tastypie: '/static/js/libs/backbone-tastypie',
serialize: '/static/js/libs/serializeObject',
text: 'text',
templates: '/static/'
}
});
require([
'app'
], function(App){
App.initialize();
});
答案 0 :(得分:1)
您是否定义了一个模块?你需要:
define([
'jquery'
],
etc