我一直得到这个Uncaught ReferenceError:当我的脚本尝试渲染模板时,x未定义错误。此脚本使用backbone.js,require.js,underscore.js和jquery.js的组合。我花了一天时间尝试在线调试和搜索答案。有人知道发生了什么吗?
代码:
define([
'jQuery',
'Underscore',
'Backbone',
'text!templates/sharingFactory.html'
], function($, _, Backbone, SharingFactoryTemplate) {
console.log('in SharingFactoryItemView');
var SharingFactoryItemView = Backbone.View.extend({
tagName: "span",
initialize: function() {
console.log('in initialize');
this.template = _.template(SharingFactoryTemplate);
console.log(this);
this.render();
},
render: function () {
console.log('in render');
var data = this.model.toJSON();
console.log(data);
this.$el.html(this.template(data));
return this;
}
});
return SharingFactoryItemView;
});
控制台日志:
in initialize SharingFactoryItemView.js:14
child
SharingFactoryItemView.js:16
in render SharingFactoryItemView.js:20
Object
SharingFactoryItemView.js:22
Uncaught ReferenceError: x is not defined