【发布时间】:2014-07-28 00:09:37
【问题描述】:
我正在尝试使用 Ember 为我的 Rails 应用程序创建一个管理后端。
这是一个说明我遇到的问题的 JsBin。
http://emberjs.jsbin.com/titix/20/edit
简而言之,我希望能够在用户点击时在其他模型列表中编辑任意模型的标题。
与 cmets 中的问题相关的 CoffeeScript:
App.ItemView = Ember.View.extend
templateName: "item"
isEditing: false
didInsertElement: ->
# 1. Is there a better way to toggle the isEditing property when the title is clicked?
view = @
@$('.title').click ->
view.toggleProperty('isEditing')
# 2. How would I unset isEditing when the user clicks on a different App.ItemView?
# 3. How do I set App.ItemController to be the controller for App.ItemView?
App.ItemController = Ember.Controller.extend
# 4. How would I then toggle the isEditing property of App.ItemView on either save of cancel from App.ItemController?
actions:
save: ->
# set isEditing is false on App.ItemView
@get('model').save()
cancel: ->
# set isEditing is false on App.ItemView
@get('model').rollback()
对任何这些问题的任何帮助都将不胜感激。
【问题讨论】:
-
kingpin2k 和 blessenm 的答案都非常好。我决定使用 kingpin2k 的,因为它更容易阅读,虽然有点冗长。
标签: ember.js