当我的脚本尝试渲染模板时,我不断收到这个 Uncaught ReferenceError: x is not defined 错误。该脚本使用了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