0

我正在学习本教程,但本教程适用于对象控制器。在 Array 控制器中,如何正确传递文本字段的对象,以便触发该模型对象的更新?

现在我可以双击,然后输入一些值,如果我按回车,我会得到值加上未定义的方法集。

Uncaught TypeError: Object asdasdasdasdasd has no method 'set'

我猜它是将原始值传递给控制器​​,然后尝试从中运行方法。我如何让它通过实际模型?

看法:

<ul>
  {{#each}}
    <li {{bind-attr class="isEditing:editing"}} {{action "editWorkout" this on="doubleClick"}}>
      {{#if isEditing}}
        {{view Ember.TextField class='edit' action="updateWorkout"}}
      {{else}}
        {{#link-to 'workout' this}} {{title}} {{/link-to}}
      {{/if}}
    </li>
  {{/each}}
  <li>
    {{newWorkoutName}}
  </li>
</ul>

控制器:

EmberWorkouts.WorkoutsController = Ember.ArrayController.extend

  actions:
    editWorkout: (workout) ->
      workout.set('isEditing', true)

    createWorkout: ->
      title = @get('newWorkoutName')

      workout = @store.createRecord('workout', title: title)
      @set('newWorkoutName', '')
      workout.save()

    updateWorkout: (workout) ->
      workout.set('isEditing', false)
      workout.save()

  isEditing: false

如果您想调查,请在此处回购:https ://github.com/ecl1pse/ember-workouts/tree/master/app

4

1 回答 1

1

itemController您可以在您的列表中指定一个,each然后ObjectController对列表中的每个项目使用一个。

{{#each itemController="workout"}}
  <li {{action editWorkout on="doubleClick"}}>
     <!-- Other stuff goes here -->
  </li>
{{/each}}

EmberWorkouts.WorkoutsController = Ember.ObjectController.extend({
    editWorkout : function(){
       this.set('isEditing', true);
    }
});

这是一个总体思路的 JSBin:http: //jsbin.com/ucanam/1038/edit

于 2013-09-13T21:08:09.027 回答