只是从@Alexanders 回答继续,但您可以在集合的解析函数中创建模型的新实例,并仅返回集合所需的 JSON 位。这是一个例子:
parse: function(response) {
if(response.data.dateOfBirth){
//Create a new model to hold the date of birth selects
var dobSelect = new DateOfBirthSelects();
dobSelect.set("days", response.data.dateOfBirth.days);
dobSelect.set("months", response.data.dateOfBirth.months);
dobSelect.set("years", response.data.dateOfBirth.years);
};
// Return the employee data to create the collection
return response.data.employees;
引用的 JSON 如下所示:
...
data:{
"employees":[
{
"employeeReference": 123
"firstName": "John"
"lastName": "Smith"
},
{
"employeeReference": 124
"firstName": "Jean"
"lastName": "Smith"
}
],
"dateOfBirth":{
"days":["01","02","03"...],
"months":["01","02","03"...],
"years":["1991","1992","1993"...],
}
}
...