mardi 29 mars 2016

How can I update component value in controller or route with ember?

My click-editable component like:

Template:

{{#if isEdit}}
  <div class="input-group">
    {{input type="text" value=editValue class="form-control"}}
    <div class="input-group-btn">
      <button type="button" class="btn no-margin-btn btn-info" {{action "updateValue"}}>{{fa-icon 'check'}}</button>
    </div>
  </div>
{{else}}
  ....
{{/if}}

And:

export default Ember.Component.extend({
  tagName: "",
  isEdit: false,
  canEdit: true,
  category: 'input',
  editValue: Ember.computed.oneWay('value'),

  actions:{
    updateValue() {
      this.sendAction('onUpdate', this.get('valueModel'), this.get('valueColumn'), this.get('editValue'), this.get('isEdit'));
    }
  }
});

Use in my template:

{{click-editable valueModel=quotationWorkItem valueColumn='name' value=quotationWorkItem.name onUpdate=(action "updateInput")}}

In the controller:

import Ember from 'ember';

export default Ember.Controller.extend({
  ....

  actions: {
    updateInput(updateModel, updateColumn, value, isEdit) {
      updateModel.set(updateColumn, value);
      updateModel.save().then(()=> {
        this.get('model').reload();
        this.set('isEdit', false);
      }, ()=> {
        alert('wrong');
      });
    }
  }
})

This code can update model value, but problem isEdit is the component value. When isEdit send to controller and set another value, it can not work. So I think can not change component value in ember controller?

this.set('isEdit', false);

The code can not work in controller. I'm using Ember 2.4.0.




Aucun commentaire:

Enregistrer un commentaire