如何将 serializeObject() 与 require.js 一起使用 错误:无法读取未定义的属性“fn”
How to use serializeObject() with require.js Error: Cannot read property 'fn' of undefined
如何使用下面的脚本,该脚本将jquery $.fn.serializeObject()与require.js一起使用?
我收到以下错误:
未捕获的类型错误:无法读取未定义的序列化对象的属性"fn".js:(匿名功能)
$.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();
它是否需要我错过的其他依赖关系?
这是我的主要.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();
});
你在定义一个模块吗?您需要:
define([
'jquery'
],
etc
相关文章:
- 未捕获的TypeError无法读取未定义的属性socialsharing
- angularjs无法读取未定义的属性then
- 无法读取未定义的属性“rid”
- 未捕获的类型错误: 无法读取未定义的属性“图像”
- 类型错误:无法读取未定义的属性“toString” - 为什么
- angular2形式-无法读取未定义的属性替换
- Highcharts错误“;无法读取未定义的属性“;
- 无法读取未定义的属性“最后”的未定义
- 运行此程序后出现错误,未捕获的类型错误:无法读取未定义的属性“推送”
- 无法读取未定义的属性“替换” - 替换 JS 生成的 HTML 中的文本
- 无法读取未定义的属性 - NodeJS,Express,Mongoose
- Google 表格脚本 - “无法读取未定义的属性”(如果不是)
- 无法读取未定义的属性“用户名” - 通过电子邮件在 Node.js 中发送表单数据
- 获取 无法读取未定义的引导轮播脚本的属性“偏移宽度”
- JavaScript 2d 数组导致“无法读取未定义的属性'未定义'”
- 无法读取未定义的属性“_handleNewFile”
- 无法读取未定义的属性“HTML5HISTORY”
- 未捕获的类型错误:无法读取未定义的属性“scrollTop”
- 无法读取未定义的属性“警报”
- 未捕获的类型错误: 无法读取未定义的 - 对象的属性