我正在尝试学习一些backbone.js,但我遇到了一些我认为应该很容易弄清楚的东西。如何获取集合中所有模型名称的列表?
我什至从主干教程中复制+粘贴:
var Song = Backbone.Model.extend({
defaults: {
name: "Not specified",
artist: "Not specified"
},
initialize: function(){
console.log("Music is the answer");
}
});
var Album = Backbone.Collection.extend({
model: Song
});
var song1 = new Song({ name: "How Bizarre", artist: "OMC" });
var song2 = new Song({ name: "Sexual Healing", artist: "Marvin Gaye" });
var song3 = new Song({ name: "Talk It Over In Bed", artist: "OMC" });
var myAlbum = new Album([ song1, song2, song3]);
console.log( myAlbum.models ); // [song1, song2, song3]
问题是 - 这并没有在控制台中给我模型名称:console.log(myAlbum.models); // [song1, song2, song3]
我得到 [child, child, child, child] - 我如何获得实际名称?