完全替换对象

时间:2018-02-25 11:35:30

标签: javascript polymer polymer-1.0

我尝试在Polymer元素中替换一个完整的对象(属性),我尝试了几种可能性,但实际上都没有...

这是我到目前为止所提出的:

prefill: function() {
    randomChild(function(r) {

        // Does not work
        var t = Object.assign(this.child, r); // r is an existing Child-object
        this.set("child", t);

        // Does not work
        this.child.firstName = r.firstName;

        // Works
        this.set("child.firstName", r.firstName);

        // Also works
        this.child.lastName = r.lastName;
        this.notifyPath("child.lastName");
    }.bind(this));
}

如何在不为每个子属性调用this.child的情况下将r替换为this.notifyPath("...")

0 个答案:

没有答案