我有一个 JavaScript 数组:
var personDetails = [
{firstName: "Anup", lastName: "Vasudeva", City: "Delhi"},
{firstName: "Vikas", lastName: "Kumar", City: "Banglore"},
{firstName: "Dannis", lastName: "Richie", City: "Texas"},
{firstName: "Ajay", lastName: "Sharma", City: "Pune"},
{firstName: "Deepak", lastName: "Aggarwal", City: "Delhi"},
{firstName: "Ajay", lastName: "Sharma", City: "Banglore"}
]
这是我打算设计的模板:
<div class="left">
<!-- Should display the first half of the rows -->
{{tmpl($data) "#someTemplate"}}
</div>
<div class="right">
<!-- Should display the rest half of the rows -->
{{tmpl($data) "#personTemplate"}}
</div>
<script id="personTemplate" type="text/x-jquery-tmpl">
{{each personDetails}}
<div class="person">
<div>${firstName}</div>
<div>${lastName}</div>
<div>${city}</div>
</div>
{{/each}}
如何操作包含前半部分行并包含后半部分行的数组。
编辑:实际上问题是用户将按原样传递数组,并且模板逻辑将数组切成两半。
谢谢阅读。