我试图按照http://ricostacruz.com/backbone-patterns/#inline_templates来避免http://ricostacruz.com/backbone-patterns/#abuse但是我有这样的典型观点:
// in app.js
App.MyView = Backbone.View.extend({
className: "ui-widget-content",
template: _.template($("#myTemplate").html()),
render: function()
{
this.$el.html(this.template(this.model.toJSON()));
}
然后我像这样包含 app.js
<script src="./js/jquery-1.7.2.min.js"></script>
<script src="./js/jquery-ui-1.8.20.custom.min.js"></script>
<script src="./js/underscore.js"></script>
<script src="./js/backbone.js"></script>
<script src="./js/app.js"></script>
浏览器抱怨$("#myTemplate")
App.MyView.template 中的行是null
(因为文档还没有准备好?)。我该怎么办?