简介:
我编写了我的自定义主干编辑器,但是骨干网无法初始化它,因为找不到它的模式。骨干网在Form.editors数组backbone-forms.js中寻找模式?如何注册自定义编辑器的架构?
详细信息:
我使用在下一种方法中初始化的主干表单:
backbone-forms.js
var Form = Backbone.View.extend({
initialize: function(options) {
//.....
//Check which fields will be included (defaults to all)
var selectedFields = this.selectedFields = options.fields || _.keys(schema);
_.each(selectedFields, function(key) {
var fieldSchema = schema[key];
fields[key] = this.createField(key, fieldSchema); // <==== Here troubles begins
}, this);
},
//....
}, {
//....
editors: {} // <===== QUESTION: where I should put my custom editor in this array???
});问题:当骨干网创建新表单时,它调用createSchema方法,如下所示:
createSchema: function(schema) {
//........
//PROBLEM: Form.editors[schema.type] is undefined
schema.type = (_.isString(schema.type)) ? Form.editors[schema.type] : schema.type;
return schema;
}而Form.editorsschema.type是未定义的。这意味着我无法创建/呈现我的自定义编辑器!
问题:在哪里/如何在Form.editors数组中注册自定义编辑器?
发布于 2014-10-22 09:05:11
您可以直接从模式中引用自定义编辑器,即引用函数本身,而不是引用字符串:
var CustomEditor = Backbone.Form.editors.Base.extend({});
var form = new Backbone.Form({
schema: {
customField: { type: CustomEditor }
}
});或者,正如您所发现的,您也可以将编辑器添加到Backbone.Form.editors中,这样您就可以使用字符串作为快捷方式。
https://stackoverflow.com/questions/26461302
复制相似问题