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
Model view controller MVC控制器在提交后更改输入字段_Model View Controller_Ember.js - Fatal编程技术网

Model view controller MVC控制器在提交后更改输入字段

Model view controller MVC控制器在提交后更改输入字段,model-view-controller,ember.js,Model View Controller,Ember.js,我的表单中有一个金额字段,在控制器中提交后乘以100。 问题是视图在进入下一页之前呈现乘法运算。 我怎样才能避免呢? 更一般地说,如何防止视图在提交后显示修改后的值 我在后端使用带有rails的ember.js,但我认为这更像是MVC的问题 这是一种观点: {{input value=model.amount mask="999[999].99" classNames="form-control" placeholder=(t 'transactions.amount')}}

我的表单中有一个金额字段,在控制器中提交后乘以100。 问题是视图在进入下一页之前呈现乘法运算。 我怎样才能避免呢? 更一般地说,如何防止视图在提交后显示修改后的值

我在后端使用带有rails的ember.js,但我认为这更像是MVC的问题

这是一种观点:

{{input value=model.amount mask="999[999].99"
        classNames="form-control" placeholder=(t 'transactions.amount')}}
这是控制器:

  actions: {
create: function() {
  var _this = this;
  var model = this.get('model');

  model.set('amount', model.get('amount') * 100);

  model.save().then(function(transaction) {
    _this.get('target').transitionToRoute(_this.get('destination'), transaction.get('id'));
  }, function(response){
    _this.set('errors', response.errors);
  });
}

}

这是一个使用计算属性的好例子,您可以在模板中使用该属性:

displayAmount: function(key, value, previousValue) {
    // setter
    if (arguments.length > 1) {
      this.set('amount', value * 100);
    }

    // getter
    return this.get('amount') / 100;
  }.property('amount')
计算属性的语法即将更改,因此您可能需要此版本:

displayAmount: Ember.computed("amount", {
  get: function() {
    return this.get("amount") / 100;
  },
  set: function(key, amount) {
   this.set("amount", amount * 100);
  }
})

你能提供你的密码吗