我有一个用 Ember + Handlebars 编写的用户注册表单。我都是新手。我想在用户键入时对表单执行实时验证。为此,我需要能够观察变化事件并做出智能响应。
我在想我可以在我的视图中声明一个email
属性并观察它的变化。然后询问服务器是否email
已经存在。
我可以想出几种方法来做到这一点,但看不到明显的赢家。我试过观察整个视图的变化,但这似乎很笨拙。现在我正在尝试创建一个new-user
对象并将逻辑存储在其中,但 Ember 想要将其连接回服务器。我在这里有点不知所措。
任何的建议都受欢迎。
这是我现在的观点:
FitMap.JoinView = Ember.View.extend({
templateName: "join",
name: null,
email: null,
password: null,
password_confirmation: null,
submit: function(event, view) {
event.preventDefault();
event.stopPropagation();
$.post("/users", {
name: this.get("name"),
email: this.get("email"),
password: this.get("password"),
password_confirmation: this.get("password_confirmation")
}, function() {
console.log("created");
})
.fail(function(response) {
console.log(response);
});
}
});