# 如何使用Backbone.js從服務器獲取模型集合？

## 最佳答案

3種最常用的設置集合的方法， 是

1. bootstrapping models in the page, and then loading them with Collection.reset();

// you can print this trough serverside in your view, (you are bootstrapping these models)
var bsModels = [{'name': 'name1'},{'name': 'name3'},{'name': 'name2'}];

// in your code you can use that bootstrapped data via the reset method.
var myModel = Backbone.Model.extend({});
var myCollection = Backbone.Collection.extend({
model: myModel
});
myCollection.reset(bsModels);

2. you can use the fetch, but it would load any and all methods, unless you override the fetch method

3. a third option is to write your own ajax call, fetching the correct amount of models, and using the same technique as in #1, using Collection.reset(data);