我正在学习本教程,但本教程适用于对象控制器。在 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