1
我想輸出一個骨幹/下劃線的對象列表,但我在骨幹中得到一個奇怪的輸出。我在期待一個解析的數據結構,但是你可以看到我回來的東西似乎沒有以正確的方式被解析。有任何想法嗎?試圖解析與骨幹網的靜態JSON
這裏是我的JSON提要:
{"1":{"title":"Test Video Collection - blah (placeholder)","image":"imagenotavailable"},"2":{"title":"Camur Exerci Gemino","image":"public:\/\/gallery\/large\/imagefield_ieMdB8.jpg"},"3":{"title":"Abdo Nutus Sed","image":"public:\/\/gallery\/large\/imagefield_LtRKG1.png"},"4":{"title":"Quidne Vereor","image":"public:\/\/images\/video\/[current-date:custom:Y\/m\/d]\/imagefield_j7lGlq.jpg"},"5":{"title":"Ludus Ratis","image":"public:\/\/video-collections\/imagefield_aB3dpQ.png"},"6":{"title":"Appellatio Dolore Huic Vulputate","image":"public:\/\/gallery\/large\/imagefield_LtRKG1.png"}}
這裏是我的代碼:
var itemModel = Backbone.Model.extend();
var ItemList = Backbone.Collection.extend({
model: itemModel,
url: 'http://l.blahcouk.sandbox:8080/franchise/videocollection/date/'
});
var ItemsView = Backbone.View.extend({
template: _.template($('#bandlist_template').html()),
render: function (eventName) {
_.each(this.model.models, function (items) {
console.log(items);
var lTitle = items.attributes['title'];
var lTemplate = this.template(items.toJSON());
$(this.el).append(lTemplate);
}, this);
return this;
}
});
var lItems = new ItemList;
var AppView = Backbone.View.extend({
el: "body",
render: function() {
var lItemsView = new ItemsView({
model: lItems
});
var lHtml = lItemsView.render().el;
$('#bands').html(lHtml);
},
initialize: function() {
var lOptions = {};
lOptions.success = this.render;
lItems.fetch(lOptions);
}
});
var App = new AppView;
這是輸出的結構:
r {cid: "c2", attributes: Object, collection: r, _changing: false, _previousAttributes: Object…}
_changing: false
_events: Object
_pending: false
_previousAttributes: Object
attributes: Object
1: Object
2: Object
image: "public://gallery/large/imagefield_ieMdB8.jpg"
title: "Camur Exerci Gemino"
__proto__: Object
3: Object
4: Object
5: Object
6: Object
__proto__: Object
changed: Object
cid: "c2"
collection: r
__proto__: s
或者如果您無權訪問更改JSON,請重寫解析以正確填充集合和模型。 –