0

每次此组件的“子分配”的内容更改时,车把模板都没有更新,我遇到了一些问题。它确实会在第一次触发事件时发生更改,即添加或删除子分配,但在那之后不会更改,即使我可以在 FireFox 开发人员工具的 Ember 调试器插件中看到“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 数据,所以如果您可以避免建议将其作为一个很好的解决方案

4

0 回答 0