理解を深めるために、コメントに基づいて以前の質問を更新しています。
//Model's
Student = Backbone.Model.extend({
defaults: {
name: ''
}
});
Students = Backbone.Collection.extend({
model: Student,
initialize: function(){
},
parse: function(resp) {
return resp;
}
});
Teacher = Backbone.Model.extend({
defaults : {
name : '',
salary : ''
}
});
Teachers = Backbone.Collection.extend({
model: Teacher,
initialize: function(){
},
parse: function(resp) {
return resp;
}
});
/**
* I Just need WrapperModel only single class instead of two so that when ever I
* make collection of this class I can dynamically bind the 'data' attribute to
* either Teachers or Students
*/
WrapperModelStudent = Backbone.Model.extend({
defaults : {
message : '',
processingStatus : ''
},
initialize : function() {
this.data = new Students([new Student({name: "Marry"}),
new Student({name: "Susan"}),
new Student({name: "Samanta"})
]);
}
});
WrapperModelTeacher = Backbone.Model.extend({
defaults : {
message : '',
processingStatus : ''
},
initialize : function() {
this.data = new Teachers();
}
});
WrapperModelStudents = Backbone.Collection.extend({
model: WrapperModelStudent,
initialize: function(){
},
parse: function(resp) {
return resp;
}
});
WrapperModelTeachers = Backbone.Collection.extend({
model: WrapperModelTeacher,
initialize: function(){
},
parse: function(resp) {
return resp;
}
});
/**
*Trying below
*/
/***
* instead of using above two need to just use below one. How to do this??
*/
WrapperModel = Backbone.Model.extend({
defaults : {
message : '',
processingStatus : ''
},
initialize : function(obj) {
this.data = obj;
}
});
WrapperModelStudentsA = Backbone.Collection.extend({
model: WrapperModel(new Students()),
initialize: function(){
},
parse: function(resp) {
return resp;
}
});
WrapperModelTeachersB = Backbone.Collection.extend({
model: WrapperModel(new Teachers()),
initialize: function(){
},
parse: function(resp) {
return resp;
}
});
wrapperModelStudent = new WrapperModelStudent({message:"success",processingStatus:"y"});
wrapperModelStudents = new WrapperModelStudents([wrapperModelStudent]);
wrapperModelTeacher = new WrapperModelTeacher({message:"success",processingStatus:"y"});
wrapperModelTeachers = new WrapperModelTeachers([wrapperModelTeacher]);
wrapperModel = new WrapperModel({message:"success",processingStatus:"y"});
wrapperModelStudentsA = new WrapperModelStudentsA([wrapperModel]);
wrapperModelTeachersA = new WrapperModelTeachersA([wrapperModel]);
console.log(wrapperModelStudents);
console.log(wrapperModelTeachers);
wrapperModel で次のエラーが発生し、そのオブジェクトを作成できません。
Uncaught TypeError: Object [object global] has no method 'set'
*************** backbone-min.js:10
g.Model
*************** backbone-min.js:10
d
*************** backbone-min.js:38
(anonymous function) sample.html:110
backbone.jsでできることはありますか??