模板在model.save()之后没有更新

时间:2014-07-22 11:01:57

标签: ember.js

我正在使用Ember-Data Fixture适配器处理表单。我的保存方法在编辑路径中如下:

actions: {
    save: function () {
        var visit = this.get('currentModel'),
            self = this,
            store = this.store;

        visit.setProperties({
            'notes': $('#notes textarea').val()
        });

        console.log('Visit Changes: ' + visit.changedAttributes());

        visit.save();

        console.log('Visit saved!');

        self.transitionTo('planning.visits.visit', visit);
}

notes字段在模板中仅作为{{notes}}引用,并在模型中作为DS.attr('string')

visit.changedAttributes()显示注释值已更改,如果我在afterModel路径中的planning.visits.visit挂钩上抛出断点,我可以获取该对象并看到该字段已更新但是模板本身永远不会更新以反映变化。

我错过了什么?

***编辑***

视图模板是

<div class="panel panel-default">
    <div class="panel-heading">
        <span class="panel-title">
            <span style="font-weight: normal; color: #666;">Visit  </span>{{visitNumber}}
        </span>
        <span class="pull-right">
            <div class="btn-group">
            <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown">
                Options
                <i class="fa fa-caret-down fa-lg"></i>
            </button>
            <ul class="dropdown-menu pull-right" role="menu">
                <li>{{#link-to 'planning.visits.edit' this}}<i class="fa fa-pencil-square-o"></i><span style="padding-left: 10px;">Edit Visit</span>{{/link-to}}</li>
                <li><a href="javascript:void(0);"><i class="fa fa-plus"></i><span style="padding-left: 10px;">Add Tasks</span></a></li>
                <li class="divider"></li>
                <li><a {{action 'delete'}}><i class="fa fa-trash-o"></i><span style="padding-left: 10px;">Delete Visit</span></a></li>
            </ul>
        </div>
     </span>
    </div>
    <div class="panel-body">

        <div class="row">
            <div class="col-lg-12">
                <p>
                    <label>Date:</label><br />
                    <strong class="value">{{startDate}}</strong> to <strong class="value">{{endDate}}</strong>
                </p>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-6">
                <p>
                    <label>Notes:</label><br />
                    <strong class="value">{{notes}}</strong>
                </p>
            </div>
        </div>

        <div class="row" style="margin-top: 20px;">
            <div class="col-lg-12">
                <ul id="detail-tabs" class="nav nav-tabs">
                    {{#link-to 'planning.visits.visit.tasks' this tagName="li"}}{{#link-to 'planning.visits.visit.tasks' this}}Tasks{{/link-to}}{{/link-to}}
                    {{#link-to 'planning.visits.visit.requirements' this tagName="li"}}{{#link-to 'planning.visits.visit.requirements' this}}Requirements{{/link-to}}{{/link-to}}
                    {{#if hasIssue}}
                        {{#link-to 'planning.visits.visit.issues' this tagName="li"}}{{#link-to 'planning.visits.visit.issues' this}}Problems<span style="margin-left: 10px;>" class="badge pull-right alert-danger">1</span{{/    link-to}}{{/link-to}}    
                    {{/if}}    
                </ul>    
            </div>    
        </div>    
        <div class="row">    
            <div id="tab-content" class="col-lg-12">    
                {{outlet tabs}}    
            </div>    
        </div>    
    </div>    
</div>

编辑模板是

<div class="panel panel-default">
    <div class="panel-heading">
        <span class="panel-title">
            <span style="font-weight: normal; color: #666;">Edit Visit </span>{{visitNumber}}
        </span>
        <span class="pull-right">
            <button class="btn btn-default" {{action 'save'}}>
                <i class="fa fa-check green" style="margin-right: 5px;"></i>Save Changes
            </button>
            {{#link-to 'planning.visits.visit' this tagName="button" classNames="btn btn-default"}}
                <i class="fa fa-ban red" style="margin-right: 5px;"></i>Discard Changes
            {{/link-to}}
        </span>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-lg-4">
                <p>             
                    {{date-picker-with-label label="Start Date" value=startDate id="startDate"}}
                </p>

            </div>
            <div class="col-lg-4">
                <p>
                    {{date-picker-with-label label="End Date" value=endDate id="endDate"}}
                </p>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-6">
                <p>
                    <label>Notes:</label>
                    {{textarea property=notes rows=3 id="notes"}}
                </p>
            </div>
        </div>      
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

问题解决了。我的PEBKAC错误。如果模板字段和要更新的字段都相同,则会有所帮助。