我有一个手机数组,其中包含从JSON数据:的Javascript模板underscore.js
var phones = [
{
"age": 0,
"id": "motorola-xoom-with-wi-fi",
"imageUrl": "img/phones/motorola-xoom-with-wi-fi.0.jpg",
"name": "Motorola XOOM\u2122 with Wi-Fi",
"snippet": "The Next, Next Generation\r\n\r\nExperience the future with Motorola XOOM with Wi-Fi, the world's first tablet powered by Android 3.0 (Honeycomb).",
"price": 150
},
我想通过使用模板显示为UL李,但我在这是全新的,所以我很卡住。 这里说,我写了代码:
<div id="phonesDiv" class="col-md-8"></div>
<script type="text/template" id="listTemplate">
<ul>
<% for (var i=0; i< phones.length; i++) { %>
<li><%=phones[i].age %></li>
<li><%=phones[i].name%></li>
<li><%=phones[i].id%></li>
<li><%=phones[i].imageUrl%></li>
<li><%=phones[i].snippet%></li>
<li><%=phones[i].price%></li>
<% } %>
</ul>
var temp = _.template($("#listTemplate").html());
var getPhones = temp({phones: phones});
$("#phonesDiv").html(getPhones);
问题是我,而不是显示图像它给我的形象的路径:
0
Motorola XOOM™ with Wi-Fi
motorola-xoom-with-wi-fi
img/phones/motorola-xoom-with-wi-fi.0.jpg
The Next, Next Generation Experience the future with Motorola XOOM with Wi-Fi, the world's first tablet powered by Android 3.0 (Honeycomb).
150