为什么把手模板没有反映出余烬属性的变化

时间:2015-02-12 06:20:09

标签: javascript ember.js handlebars.js computed-observable

我遇到一些问题,每当这个组件的'subAllocations'的内容发生变化时,把手模板都不会更新。 它会在第一次触发事件时更改,即添加或删除subAllocations,但之后不会更改,即使我可以在Ember调试器插件中看到FireFox开发人员工具的计算值已更改为'hasSubAllocations'

App.AllocationAllocationRowComponent = App.CollapsableComponent.extend({
    layoutName: 'components/allocation/allocation/row',
    tagName: "tr",

    hasSubAllocations: Em.computed.notEmpty("allocation.subAllocations"),

    updateAllocation: function (data) {
        var newAllo = data.allocation;
        this.set("allocation.subAllocations", Em.copy(newAllo.subAllocations));
        this.sendAction("onRefreshAirSpaces", data.updatedAirSpaces);
    },

    actions: {
        addSubAllocation: function(){
            var alloc = this.get("allocation");
            var self = this;
            Em.$.ajax({
                type: 'POST',
                url: '/allocation/addSubAllocations',
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify(alloc),
            }).then(function (data) {
                self.updateAllocation(data);
            });            
        },

        subAllocationRemoved: function (subAllocation) {
            var self = this;
            Ember.$.ajax({
                type: 'POST',
                url: '/allocation/RemoveSubAllocation/',
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify(subAllocation),
            }).then(function (data) {
                self.updateAllocation(data);
            });
        },
    },
});

来自车把模板

`<span {{bind-attr class="hasSubAllocations:hidden:"}}>content here</span>`
我错过了什么吗?

我们没有使用ember数据,所以如果你可以避免建议那个很棒的解决方案

0 个答案:

没有答案