Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Ember.js中,使用Ember验证,如何从控制器触发模型大小验证?_Ember.js - Fatal编程技术网

在Ember.js中,使用Ember验证,如何从控制器触发模型大小验证?

在Ember.js中,使用Ember验证,如何从控制器触发模型大小验证?,ember.js,Ember.js,我在试船坞的混音器。我有一个NewUser对象,看起来像这样: App.NewUser = Ember.Object.extend(Ember.Validations.Mixin, { name: null, email: null, password: null, password_confirmation: null, validations: { name: { presence: true } }, watchChanges:

我在试船坞的混音器。我有一个NewUser对象,看起来像这样:

App.NewUser = Ember.Object.extend(Ember.Validations.Mixin, {
  name: null,
  email: null,
  password: null,
  password_confirmation: null,

  validations: {
    name: {
      presence: true
    }
  },

  watchChanges: function() {
    // Live validations...
    this.validate();
  }.observes("name", "email", "password", "password_confirmation")
});
我有一个控制器,其中包含我的
submit
方法:

App.JoinController = Ember.ObjectController.extend({
  submit: function() {
    // Run validations again
    // Send to server if okay
    this.get("model").validate();
  }
});
以及将模型链接到视图的管线:

App.JoinRoute = Ember.Route.extend({
  model: function() {
    return App.NewUser.create();
  }
});
(这也是一个将提交方法转发给控制器的视图)


我不明白的是如何从控制器连接回模型对象以运行
.validate()
。看起来我应该能够在控制器的submit方法中做一些事情,比如
this.get(“model”).validate()
,但这不起作用。我应该如何进行这项工作?

我想您应该尝试访问控制器
内容
属性,而不是
模型
,类似这样的操作应该可以:

App.JoinController = Ember.ObjectController.extend({
  submit: function() {
   // Run validations again
   // Send to server if okay
   this.get("content").validate();
  }
});
请参阅以获取伪工作演示


希望能有所帮助。

我想您应该尝试访问控制器
内容
属性,而不是
模型
,类似的操作应该可以:

App.JoinController = Ember.ObjectController.extend({
  submit: function() {
   // Run validations again
   // Send to server if okay
   this.get("content").validate();
  }
});
请参阅以获取伪工作演示

希望有帮助。

请试试这个

App.JoinController = Ember.ObjectController.extend({
   submit: function() {
      this.validate().then(function(){
         //if valid do actions
      }).catch(function(){
        //errors
     })
   }
});
请试试这个

App.JoinController = Ember.ObjectController.extend({
   submit: function() {
      this.validate().then(function(){
         //if valid do actions
      }).catch(function(){
        //errors
     })
   }
});