以控制器的方法为参数调用辅助方法

时间:2018-07-02 14:07:12

标签: javascript model-view-controller helper

我正在尝试从Helper类中调用方法(clickRegister):

int counter = 0;
while (true){
    try{
        // do something
        break;
    } catch (IOException e) {
        e.printStackTrace();
        counter++;

        if (counter >= 10)
            throw new RuntimeException(e);
    }
}

在我的控制器上

  class AdminPanelHelper {
  constructor() {

  }
  static clickRegister(callback){
    var promise = new Promise(function(res,rej) {
      $('.register-link').click(function() {
        $('.admin-body').fadeOut(function() {
          callback();
          res();
        })
      });
    })
    promise.then(function() {
      $('.admin-body').fadeIn();
    })
  }
}

但是我在控制台上看到错误'View.js:7 Uncaught TypeError:无法读取未定义的属性'_element'

我将Mvc设计伙伴与RegisterView扩展View一起使用。 真的不知道出什么问题了,该元素在“ this._registerView = new RegisterView($('。admin-body'));”中声明。

编辑:

添加RegisterView类和View类:

class AdminPanelController {

  constructor() {
    this._loginView = new LoginView($('.admin-body'));
    this._registerView = new RegisterView($('.admin-body'));
  }

  showLogin(){
    this._loginView.update();
    var e = this;
    AdminPanelHelper.clickRegister(e._registerView.update);
  }

}

查看课程:

class RegisterView extends View {
  constructor(element) {
    super(element);
  }

  template(){
      return `
      <div class="form-body">
      <div class="welcome">
        <h2 class="login-welcome">This is only for test, your account will be deleted after 20min</h2>
      </div>
        <form id="register" class="" action="register" method="POST">
        <input type="text" name="user" id="user" value="" placeholder="USER">
          <input type="email" name="email" id="email" value="" placeholder="EMAIL">
          <input type="password" name="password" id="password" value="" placeholder="PASSWORD">
          <input type="password" name="passwordConf" id="passwordConf" value="" placeholder="CONFIRM PASSWORD">
          <input class="btn btn-primary register-user" type="submit" value="Register" id='regsubmit'>
        </form>
        <div class="register-link-body">
          <span>Back to <a class="login-link">login</a></span><br>
        </div>
        </div>
      `
  }
}

0 个答案:

没有答案