我正在评估用于建模树的 Backbone-Relational 插件。我有以下示例代码
var SurveyTreeNode = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'questions',
relatedModel: 'SurveyTreeNode'
}]
});
var survey = {
id: 1,
questions: [
{
id: 2,
text: 'What is your name?'
},
{
id: 3,
text: 'What hours do you work?',
questions: [
{
id: 3,
text: 'On Monday?'
},
{
id: 4,
text: 'On Tuesday?'
}
]
}
]
};
var questionTree = new SurveyTreeNode(survey);
产生(在 Google Chrome 控制台中):
no model, key or relatedModel (function (){ parent.apply(this, arguments); }, "questions", undefined)
我已将此代码加载到 jsfiddle 中,因为错误没有完全如上显示(显示可以扩展的子元素):http: //jsfiddle.net/hoffmanc/XsDQu/