我正在关注本指南:http ://emberjs.com/guides/getting-started/toggle-todo-editing-state/
所以我写了这段代码:
App.PostEditController = Ember.ObjectController.extend
headerTitle: 'Editing post'
buttonTitle: 'Edit'
destroy: ->
@content.deleteRecord()
@store.commit()
@transitionToRoute('posts')
save: ->
@content.save().then =>
@transitionToRoute('post', @content)
cancel: ->
console.log("Canceling! " + @content)
if @content.isDirty
@content.rollback()
@transitionToRoute('post', @content)
后控制器:
App.PostController = Ember.ObjectController.extend
commentsVis: false
isEditing: false
showComments: () ->
this.set("commentsVis", true)
@transitionToRoute('comments', post)
editMode: ->
this.set("isEditing", true)
@transitionToRoute('post.edit')
路线
EmberJs.PostRoute = Ember.Route.extend
model: (params) ->
App.Post.find(params.post_id)
setupController: (controller, model) ->
controller.set('content', model)
controller.set('isEditing', false)
EmberJs.PostEditRoute = Ember.Route.extend
model: (params) ->
App.Post.find(params.post_id)
setupController: (controller, model) ->
controller.set('content', model)
意见:
邮政:
<h1>{{title}} / {{parseDate created}} by {{user.email}}</h1>
<p>{{body}}</p>
<div id="discussion">
{{#unless commentsVis}}
<a href="#" {{action 'showComments' this}}>View discussion</a>
{{/unless}}
</div>
{{outlet}}
{{#unless isEditing}}
<button type="submit" {{action 'editMode'}}>
Edit
</button>
{{/unless}}
编辑:
<h1>Edit Post</h1>
<form>
<div class="input string">
<label>Title</label>
{{view Ember.TextField valueBinding='title' name='title' viewName='titleField'}}
</div>
<button type="submit" class="button" {{action save}}>
Edit
</button>
<button type="submit" class="button alert" {{action destroy}}>
Delete
</button>
<a href="#" {{action cancel}}>Cancel</a>
</form>
{{outlet}}
我有两个问题:
当我单击取消时,正在加载正确的模板,isEditing 更改为 false,但编辑按钮仍处于隐藏状态。
@transitionToRoute('post', @content) 行将我移动到一个未定义的页面,似乎@content 不是模型,而是 DS.RecordArray。昨天它工作得很好,但似乎其他一些变化打破了它。
在此先感谢,BBLN!