我的主干观点面临问题。我正在尝试渲染一组日对象,并且每个日对象都包含另一个时间对象数组。我从我的 API 中获取集合就好了,但是一旦呈现它就会显示:
从控制台可以看出,这基本上是我收藏的最后一件。API 调用实际上返回有效的输出。
这是我的模板的样子:
<table id="stbl" class="table table-striped table-bordered">
<% _.each(slots, function(slot) { %>
<tr>
<td>
<strong> <%- slot.startDate %> </strong>
</td>
<% _.each(slot.timeSlots, function(t) { %>
<td>
<button id="le-time" class="btn btn-primary"><%- t %></button>
</td>
<% }); %>
</tr>
<% }); %>
</table>
这是我的收藏:
kronos.Slots = Backbone.Collection.extend({
model: kronos.Slot,
url: '/api/freeslots'
});
这就是我的观点:
kronos.TableView = Backbone.View.extend({
initialize: function () {
var self = this;
this.collection.fetch({
success: function (collection, response) {
_.each(response, function (i) {
console.log(i);
});
self.render();
},
data: $.param({ orgID: 4 })
});
this.collection.on('reset', this.render, this);
},
template: _.template($('#slotsTable').html()),
render: function () {
$('#slotsContainer').html(this.template({
slots: this.collection.toJSON()
}));
}
});
fetch 调用返回的 JSON 数据
[
{"id":0, "startDate":"04/11/2013", "serviceID":241, "providerID":223, "timeSlots": ["09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00"]},
{"id":0, "startDate":"05/11/2013", "serviceID":241, "providerID":223, "timeSlots": ["09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00"]}
]
你能帮我理解我在这里做错了什么吗?
谢谢