2013-11-04 26 views
1

我所有的模特屬性在默認情況下觀察到灰燼,所以當我在形式上創造新的紀錄,我的應用程序更新,其中模型被用於(帖子櫃檯所有的地方,用的標題頭等等),禁用觀察者/物業,直到保存記錄

我不希望這樣的行爲,直到我的記錄是有效的,並保存在數據庫中。

控制器:

ProManager.TasksNewController = Ember.ObjectController.extend 
    headerTitle: 'Create' 
    buttonTitle: 'Create' 

    actions: 
    save: -> 
    if @content.validate() 
    @content.save().then (=> 
     @transitionToRoute('task', @content) 
    ), (error) => 
     @content.becameError() 
    else 
     @content.set('errors', @content.get('validationErrors.fullMessages')) 

模板:

<form id="task-form"> 
<fieldset> 
    <div> 
     <label {{bindAttr for="titleField.elementId"}}>Title</label> 
     {{view Ember.TextField valueBinding='title' name='title' viewName='titleField'}} 
    </div> 
    <div> 
     <label {{bindAttr for='descriptionField.elementId'}}>Last Name</label> 
     {{view Ember.TextField valueBinding='description' name='description' viewName='descriptionField'}} 
    </div> 
    <a href='#' {{action save}} class='btn btn-success'>{{buttonTitle}}</a> 
</fieldset> 

我不想更新/顯示器的{{title}}或{{說明}}頁直到保存:

感謝您的幫助:)

下面是一個很好的示例:http://jsbin.com/arebem/2/edit, 創建新用戶時,在保存之前會在用戶列表中更新first_name。

好吧,我有某種這一解決方案,我們可以證明它,只有當它不髒。

{{#unless isDirty}} 
<div class="accordion-on"> 
    <h3>#{{id}} {{title}}</h3> 
    <div> 
     <div>{{title}}</div> 
     <div>{{description}}</div> 
    </div> 
</div> 
{{/unless}} 

回答

0

解模板#1

{{#unless isDirty}} 
<div id="task-lists" class="well"> 
    <h5>#{{id}} {{title}}</h5> 
    <button class="btn btn-small" {{action 'openModal' 'TasksNew' this 'Task' }}>New Task</button> 

    {{#each task in content.tasks}} 
     {{ render "tasks/show_accordion" task }} 
    {{/each}} 
</div> 
{{/unless}} 

解模板#2(設置隱藏css類如果未保存)

<div {{bind-attr class=":accordion isDirty:hidden"}}> 

<h3>#{{id}} {{title}}</h3> 
<div> 
    <div>{{title}}</div> 
    <div>{{description}}</div> 
</div> 
</div>