0
我想從服務器檢索對象的列表,並使用Backbone.js 在html上呈現它但面臨「 - 無法解決」的錯誤。BackBone.js:「_無法解析」
我的代碼如下:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter- bootstrap/3.2.0/js/bootstrap.min.js">
</head>
<body>
<div class="container">
<div class="page">
</div>
</div>
<script type="text/template" id="product-list-template">
<table class="table striped">
<thead>
<tr>
<th>Category</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<% _.each(products, function(product){ %>
<tr>
<td><%= product.get('category')%></td>
<td><%= product.get('description')%></td>
</tr>
<%}); %>
</tbody>
</table>
</script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"> </script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script type="text/javascript">
var Products = Backbone.Collection.extend({
url: '/VeggieFresh/veggie/product/1'
});
var ProductList = Backbone.View.extend({
el: '.page',
render: function(){
var that = this;
var products = new Products();
products.fetch({
success : function(products){
var template = _.template($('#product-list-template').html(), {products: products.models});
that.$el.html(template);
}
});
}
});
var Router = Backbone.Router.extend({
routes : {
'':'home'
}
});
var productList = new ProductList();
var router = new Router();
router.on('route:home', function(){
console.log('Backbone loaded.');
productList.render();
});
Backbone.history.start();
</script>
</body>
</html>
錯誤如下: org.apache.jasper.JasperException:無法編譯類JSP:
An error occurred at line: 30 in the jsp file: /index.jsp
_ cannot be resolved
27: </tr>
28: </thead>
29: <tbody>
30: <% _.each(products, function(product){ %>
31: <tr>
32: <td><%= product.get('category')%></td>
33: <td><%= product.get('description')%></td>
An error occurred at line: 30 in the jsp file: /index.jsp
products cannot be resolved to a variable
27: </tr>
28: </thead>
29: <tbody>
30: <% _.each(products, function(product){ %>
31: <tr>
32: <td><%= product.get('category')%></td>
33: <td><%= product.get('description')%></td>
任何幫助/建議進行這個問題是高度讚賞。