您可以覆盖默认
parse
功能以提供XML支持。它应该返回转换为JSON的数据http://backbonejs.org/#Collection-parse将渲染绑定到
reset
事件,而不是refresh
Backbone <1.0或sync
Backbone> = 1.0 的事件
它可能看起来像这样
var Book = Backbone.Model.extend();var Books = Backbone.Collection.extend({ model: Book, url: "books.xml", parse: function (data) { var $xml = $(data); return $xml.find('book').map(function () { var bookTitle = $(this).find('name').text(); return {title: bookTitle}; }).get(); }, fetch: function (options) { options = options || {}; options.dataType = "xml"; return Backbone.Collection.prototype.fetch.call(this, options); }});var bookListView = Backbone.View.extend({ initialize: function () { this.listenTo(this.collection, "sync", this.render); }, render: function () { console.log(this.collection.toJSON()); }});var bks = new Books();new bookListView({collection: bks});bks.fetch();还有一个演示http://jsfiddle.net/ULK7q/73/



