0
我寫我的自定義骨幹編輯,但骨幹無法初始化它,因爲它無法找到架構。 Backbone在Form.editors
數組中尋找模式backbone-forms.js
? 如何註冊我的自定義編輯器的模式?
方式:
我使用的是在接下來的方式初始化骨幹形式:
骨幹,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.editors [schema.type]未定義。這意味着我無法創建/渲染我的自定義編輯器!
問題:哪裏/我該如何在Form.editors
數組中註冊我的自定義編輯器?
爲什麼不直接在對象中添加「編輯器」而不是在第二個參數中給出散列? (你試過嗎?) – 2014-10-20 10:13:12
@queval_j我通過添加'Backbone.Form.editors.MyCustomEditor = MyCustomEditor; – 2014-10-20 10:33:32