当我使用主干在我的模型中加载时,.fetch()
Backbone Relational 会为它添加的每个问题触发一个 add:survey_question(这与survey_questions
通过 .add() 将某些内容加载到我的集合中会发生的情况相同。更糟糕的是,add:survey_questions 不会' 尊重comparator
我的survey_questions 收藏。
我想要一种方法来使发生的 add:survey_questions 静音
侦听调查模型 (SurveyBuilder) 和问题模型(嵌入在 SurveyQuestion 模型中)上的所有事件时的 Console.log 输出
//START of .fetch() on the Survey Model
SurveyBuilder
["relational:change:survey_questions", child, Array[3], Object]
app.js:25338
SurveyBuilder
["add:survey_questions", child, child, Object]
app.js:25338
Question
["add:survey_question", child, Backbone.Collection, Object]
app.js:25575
SurveyBuilder
["add:survey_questions", child, child, Object]
app.js:25338
Question
["add:survey_question", child, Backbone.Collection, Object]
app.js:25575
SurveyBuilder
["add:survey_questions", child, child, Object]
app.js:25338
Question
["add:survey_question", child, Backbone.Collection, Object]
app.js:25575
SurveyBuilder
["sync", child, Object, Object]
app.js:25338
//START OF Manual .add()
SurveyBuilder
["add:survey_questions", child, child, Object]
app.js:25338
SurveyQuestion
["change:question_number", child, 4, undefined]
app.js:25578
SurveyQuestion
["change", child, undefined]
app.js:25578
这是我的模型:
m.Question = m.BaseModel.extend({
urlRoot: '/api/questions',
initialize: function(){
if(this['type']) {
this.set('type', this['type']);
} else if(this.get('type')) {
this.type = this.get('type');
}
m.BaseModel.prototype.initialize.apply(this, arguments);
},
defaults: {
question_text: '',
question_number: 1,
comment_field: true
},
calculateProperties: function(){
return {
'question_id': this.getID()
};
},
subModelTypes: {
'Numeric': 'APP.Models.NumericQuestion',
'MultipleChoice': 'APP.Models.MultipleChoiceQuestion',
'Checkboxes': 'APP.Models.CheckboxesQuestion',
'FreeText': 'APP.Models.FreeTextQuestion',
'TimePeriod': 'APP.Models.TimePeriodQuestions',
'Sorting': 'APP.Models.SortingQuestion',
'Grading': 'APP.Models.GradingQuestion',
'Slider': 'APP.Models.SliderQuestion',
'AgreeDisagree': 'APP.Models.AgreeDisagreeQuestion',
'YesNo': 'APP.Models.YesNoQuestion'
}
});
m.SurveyQuestion = m.BaseModel.extend({
defaults: {
'question_number': 1
},
relations: [{
type: Backbone.HasOne,
key: 'question',
relatedModel: 'APP.Models.Question',
includeInJSON: '_id',
reverseRelation: {
type: Backbone.HasMany,
key: 'survey_question',
includeInJSON: false
}
}]
});
m.Survey = m.BaseModel.extend({
urlRoot: '/api/surveys',
defaults: {
start_date: moment().format('YYYY-MM-DD'),
end_date: moment().add('weeks', 3).format('YYYY-MM-DD'),
title: moment().format('MMMM') + ' Economist Survey'
},
relations: [{
type: Backbone.HasMany,
key: 'survey_questions',
relatedModel: 'APP.Models.SurveyQuestion',
collectionType: 'APP.Collections.SurveyQuestions',
includeInJSON: true,
reverseRelation: {
key: 'survey',
includeInJSON: true
}
}]
});