我正在尝试创建一个非常简单的东西 - 登录。
这是我的模板:
<script type="text/x-handlebars" data-template-name="login">
<div class="row well">
<form class="form-inline">
{{input value=email type="text" placeholder="Email?"}}
{{input value=password type="password" placeholder="Password?"}}
{{#view App.LoginView}}
<button id="login-button" type="submit" class="btn">Sign in</button>
{{/view}}
</form>
{{#if not_logged}}
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong> Best check yo self, you're not looking too good.
</div>
{{/if}}
</div>
</script>
风景:
App.LoginView = Ember.View.extend(
{
tagName: "span",
click: function()
{
this.$("#login-button").button("loading");
this.get("controller").send("do_login");
}
});
控制器:
App.LoginController = Ember.Controller.extend(
{
is_logged: true,
do_login: function()
{
/** some ajax comes here **/
}
});
因此,用户单击按钮,我将其状态更改为“正在加载”。问题是如果登录失败,我如何向视图发出信号,以便我可以这样做。$("#login-button").button("reset"); ?