【问题标题】:Deleting a Kinetic.Node : remove() or destroy()?删除 Kinetic.Node:remove() 还是 destroy()?
【发布时间】:2014-05-28 09:19:31
【问题描述】:

我有一个 MVC 应用程序,我在我的一个视图中使用 KineticJS。我想知道如果我要从组中并最终从数据库中删除形状或图像,使用哪种方法更好。是destroy() 还是remove()?

【问题讨论】:

    标签: javascript canvas kineticjs


    【解决方案1】:

    使用 remove,您可以从画布中删除一个节点,但如果您愿意,您可以稍后再次使用它。 使用destroy,节点会被完全销毁,不能重用。

    所以,如果你想完全删除一个元素,使用destroy,否则使用remove。

    【讨论】:

    • 所以你是说 destroy() 在我的情况下更好?
    • 可以,如果以后不想再使用的话,还是用destroy比较好。
    • 太棒了!谢谢。我只是想知道有人实际上如何使用已删除的节点?
    【解决方案2】:

    这是下面的源代码.... destroy() 看起来它调用了 remove() 不是吗?所以基本上它们是多余的?

    remove: function () {
        var c = this.getParent();
        return c && c.children && (c.children.splice(this.index, 1), c._setChildrenIndices(), delete this.parent), this._clearSelfAndDescendantCache(q), this._clearSelfAndDescendantCache(b), this._clearSelfAndDescendantCache(t), this._clearSelfAndDescendantCache(j), this._clearSelfAndDescendantCache(a), this
    },
    destroy: function () {
        Kinetic._removeId(this.getId()), Kinetic._removeName(this.getName(), this._id), this.remove()
    },
    

    【讨论】:

    • 你是对的。我不完全理解这段代码。但你说得有道理。我希望有人能解释一下。
    猜你喜欢
    • 2017-11-30
    • 1970-01-01
    • 2015-07-31
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 2013-02-26
    • 2019-07-24
    相关资源
    最近更新 更多