我有这样的表格(来自小部件模板):
'<div>' +
' <form data-dojo-type="dijit.form.Form" data-dojo-attach-point="form" method="POST"> ' +
' <label for="${id}_workspace">Workspace name</label> ' +
' <input name="workspace" id="${id}_workspace" data-dojo-attach-point="workspace" data-dojo-type="app.ValidationWorkspace" />' +
' <label for="${id}_password1">Password</label> ' +
' <input name="password[0]" id="${id}_password1" data-dojo-attach-point="password1" data-dojo-type="app.ValidationPassword" />' +
' <label for="${id}_password1">Confirm password</label> ' +
' <input name="password[1]" id="${id}_password2" data-dojo-attach-point="password2" data-dojo-type="app.ValidationPassword" />' +
' <input type="submit" data-dojo-attach-point="button" data-dojo-type="app.BusyButton" label="Create!" />' +
' </form>' +
'</div>',
在代码中,我写道:
data = {};
data.workspace = that.workspace.get('value');
data.password = [];
data.password[0] = that.password1.get('value');
data.password[1] = that.password2.get('value');
// Store the data
g.stores.workspacesAnon.put(data).then(
function(res){
console.log("Jsonrest put(data) returned OK: " + json.toJson(res) );
that.button.cancel();
}
);
两个实际问题:
如果我使用 that.form.value.email 而不是 that.password1.get('value'),有时会将过时的值提交给表单 (!)。例如,如果我在密码 2 字段中输入一些内容并立即按回车,实际提交会发生在 Dojo 中的预期?怎么会这样?
有没有更好的方法来获取表单的值,以便 'password[0]' 和 'password[1]' 自动成为一个数组等?