ember.js如何从控制器弹出模式

ember.js如何从控制器弹出模式,ember.js,Ember.js,我成功地从路由中使用此代码弹出boostrap模型: this.render("login-modal", { into: 'application', outlet: 'modal' }); 我有一个登录模板,操作是通过控制器处理的。如果通过控制器登录失败,我想做的是弹出模式 登录控制器: App.LoginController = Ember.Controller.extend({ needs: ['application'], actions: { submit:

我成功地从路由中使用此代码弹出boostrap模型:

this.render("login-modal", {
  into: 'application',
  outlet: 'modal'
});
我有一个登录模板,操作是通过控制器处理的。如果通过控制器登录失败,我想做的是弹出模式

登录控制器:

App.LoginController = Ember.Controller.extend({
  needs: ['application'],

  actions: {
  submit: function() {
  var username = this.get('username');
  var password = this.get('password');
  var self = this;

  var postData = JSON.stringify({
    "username": username,
    "password": password
  });

  self.set('errorMessage', null);

  $.ajax({
    type: 'POST',
    contentType: 'application/json',
    url: 'api/auth',
    dataType: "json",
    data: postData,
    success: function(response){
      self.set('errorMessage', response.message);

      if (response.success) {

        self.set('token', response.token);
        self.set('loginstatus', 'success');

        var appController = self.get('controllers.application');
        appController.set('token', response.token);

        self.transitionToRoute('/');
      }

      if (response.message) {
          //console.log('login failed');
          self.get('login').render("login-modal-failed", {
          into: 'application',
          outlet: 'modal'
        });
      }
    },
    error: function() {
      alert("An error occurred while processing JSON file.");
    }
  });
 }
}
这是失败的代码:

if (response.message) {
  //console.log('login failed');
  self.get('login').render("login-modal-failed", {
      into: 'application',
      outlet: 'modal'
  });
}
错误:未捕获类型错误:无法读取未定义的属性“render”

登录模板

<script type="text/x-handlebars" data-template-name="login">
  <h1>LOGIN</h1>
  <p>Please enter login info</p>

  <form class="form-inline" role="form" {{action 'submit' on="submit"}}>
    <div class="form-group">
      {{input type="text" class="form-control" placeholder="Username" value=username}}
    </div>
    <div class="form-group">
      {{input type="password" class="form-control" placeholder="Password" value=password}}
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
  {{#if errorMessage}}
    <br />
    <div class="alert alert-warning alert-dismissible" role="alert">
      <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      <strong>Warning!</strong> Wrong username and/or password.
    </div>
  {{/if}}
</script>

登录
请输入登录信息

{{input type=“text”class=“form control”placeholder=“Username”value=Username} {{input type=“password”class=“form control”placeholder=“password”value=password} 提交 {{{#如果错误消息}
&时代;接近 警告错误的用户名和/或密码。 {{/if}
引导模式组件

<script type="text/x-handlebars" data-template-name="components/my-modal">
  <div class="modal fade">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">{{title}}</h4>
        </div>
        <div class="modal-body">
          {{yield}}
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary" {{action 'ok'}}>OK</button>
        </div>
      </div>
    </div>
  </div>
</script>

{{title}}
{{yield}}
好啊
基于上述组件的引导模式模板

<script type="text/x-handlebars" data-template-name="login-modal-failed">
  {{#my-modal title='Login Failed' ok='failed'}}
    Login failed - wrong username/password!
  {{/my-modal}}
</script>

{{{#我的模式标题='Login Failed'ok='Failed'}
登录失败-用户名/密码错误!
{{/my modal}}

以下是一个示例在您的示例中,
这个
是什么?你需要显示更多的代码。第一个表示路线,第二个表示控制器。我希望代码足够了哈哈。无论如何,再次感谢你的指点:D