在 Javascript 'for' 循环中,是否可以传递主干集合而不是数组?例如:在下面的示例代码中schools
是一个集合,而不是一个数组。这怎么可能?
var selectedSchool;
var addClasses = function(schools){
selectedSchool = Alloy.Collections.schools.at(0);
for(var i = 0; i < schools.length; i++){
var school = Backbone.Collections.schools.at(i);
var label = Ti.UI.createLabel({
text: schools.get('name'),
height:'auto',
};
这里是在模型schools
中定义为集合的地方school
:
exports.definition = {
config : {
"defaults": {
"title": "-",
"description": "-"
},
"adapter": {
"type": "rest",
"collection_name": "schools",
"base_url" : "/schools/",
}
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// Extend, override or implement Backbone.Collection
urlRoot: '/schools/',
name: 'schools',
});
return Collection;
}
}
任何帮助将不胜感激。