我收到Uncaught ReferenceError
文本:ID 未定义异常
Uncaught ReferenceError: Id is not defined
(anonymous function)
y.templateunderscore-min.js:5
Backbone.View.extend.renderProductView.js:13
Backbone.View.extend.renderProductListView.js:15
Backbone.View.extend.initializeProductListView.js:4
g.Viewbackbone-min.js:34
dbackbone-min.js:38
appRouter.on.productsList.fetch.successAppRouter.js:18
f.extend.fetch.a.successbackbone-min.js:23
f.Callbacks.ojquery-1.7.2.min.js:2
f.Callbacks.p.fireWithjquery-1.7.2.min.js:2
wjquery-1.7.2.min.js:4
f.support.ajax.f.ajaxTransport.send.d
存储在外部文件中,模板如下所示:
<a class="thumbnail" href="#/products/<%= Id %>">
<img alt="" src="/Content/img/<%= Thumbnail %>" />
<h5><%= Title %></h5>
<p><%= Price %></p>
<p><%= Details %></p>
</a>
其对应的视图将render
方法定义为:
define(['jquery', 'underscore', 'backbone', 'text!templates/product.html'], function ($, _, Backbone, productTemplate) {
var ProductView =
...
render: function() {
var data = {};
var compiledTemplate = _.template(productTemplate, data);
this.$el.append(compiledTemplate);
}
...
什么可能导致抛出异常?谢谢!
编辑
模型定义了默认值,例如:
defaults: {
Id: '00000000-0000-0000-0000-000000000000',
Price: 0.0,
Category: 'empty',
Title: 'untitled',
Details: '',
Thumbnail: ''
}