javascriptember.jshandlebars.jsember-componentsember-controllers

ember computed in input value from each loop


i have a input element on ember, while the value is come from each condition

{{#each items as |item|}}
        <div class="form-group">
          <label class="col-sm-3 control-label">Judul {{item.no}}</label>
          <div class="col-sm-9 input-group">
            {{input class="form-control" value=item.title placeholder="Tambah judul" type="text"}}
            <span class="input-group-btn">
              <a class="btn btn-default remove_detail" type="button" onclick={{action 'decreaseTitle'}}><i class="fa fa-times"></i></a>
            </span>
          </div>
        </div>
{{/each}}

i just wanna "watch" while the input in value=item.title has change from ember computed. how to do that ?


Solution

  • Please see the following twiddle for an illustration of a computed property definition that is dependent on a property of an item within an array. You can check application.js controller.

    Ember.computed('items.@each.title', function(){...})
    

    does the trick for you.