1

我正在使用 ember-validations,Ember 在 Add 和 Edit 控制器之间使用相同验证规则的正确方法是什么?

这样做不是 DRY 方式

App.UsersAddUserController.reopen(Ember.Validations.Mixin, {
    validations: {
        name: {
            presence: true,
            length: { minimum: 3 }
        },
        surname: {
            presence: true,
            length: { minimum: 3 }
        }
    },
});

App.UsersEditUserController.reopen(Ember.Validations.Mixin, {
    validations: {
        name: {
            presence: true,
            length: { minimum: 3 }
        },
        surname: {
            presence: true,
            length: { minimum: 3 }
        }
    },
});
4

2 回答 2

0

任何一个

App.UsersEditUserController = App.UsersAddUserController.extend({})

或者告诉路由使用哪个控制器

App.UsersEditUserRoute = Ember.Route.extend({
  controllerName: 'usersAddUser'
})
于 2014-06-20T12:01:54.487 回答
0

这样做:

App.UserValidations = {
  validations: {
    name: {
      presence: true,
      length: { minimum: 3 }
    },
    surname: {
      presence: true,
      length: { minimum: 3 }
    }
  }
}

App.UsersAddUserController.reopen(Ember.Validations.Mixin, App.UserValidations);
App.UsersEditUserController.reopen(Ember.Validations.Mixin, App.UserValidations);
于 2014-07-25T09:55:47.190 回答