我正在尝试验证表单。当我指定默认数据来填充不匹配的表单时,而不是通过commit
验证,我预计会记录错误(这是正确的):
Errors: {"confirmedUsername":{"type":"match","message":"Usernames must match!"}}
JsFiddle:http://jsfiddle.net/franklovecchio/FkNwG/173/
当我指定匹配的默认数据时,通过commit
验证,我得到一个实际的控制台错误:
Uncaught TypeError: Cannot call method 'set' of undefined
JsFiddle:http://jsfiddle.net/franklovecchio/FkNwG/172/。
是什么给出的?
答案 0 :(得分:0)
弗兰克从文档中看来你做错了。
http://jsfiddle.net/FkNwG/176/
您可以创建表单而不将其绑定到模型。例如,要为简单的数据对象创建表单:
var form = new Backbone.Form({
data: { id: 123, name: 'Rod Kimble', password: 'cool beans' }, //Data to populate the form with
schema: {
id: { type: 'Number' },
name: {},
password: { type: 'Password' }
}
}).render();
然后代替form.commit(),执行:
var data = form.getValue(); //Returns object with new form values
我刚刚将commit
更改为getvalue()