Giter VIP home page Giter VIP logo

Comments (7)

livoras avatar livoras commented on July 21, 2024

@ibufu 一般情况下是不会直接操作Element的children的,Element应该在每次状态变更的时候重新构造。不知道你的问题具体是什么,能否提供一下具体代码呢?

from simple-virtual-dom.

ibufu avatar ibufu commented on July 21, 2024

@livoras 建好了一个Element后,需要做增删改,所以要往element的children里push,或者根据我设置的id遍历children修改数据。(因为只是很局部的操作)操作起来很麻烦,而且push的时候,还要更新count,不然diff的时候index就会出错。

from simple-virtual-dom.

ibufu avatar ibufu commented on July 21, 2024

@livoras 如果能开一个方便修改element的接口就好了

from simple-virtual-dom.

livoras avatar livoras commented on July 21, 2024

@ibufu 即使是非常小的局部修改,也应该重新构造整棵虚拟DOM。一个虚拟DOM树一旦构造就不应该手动修改,它只是保存目前DOM树的状态。状态变更就应该构造新的树,再和原来的树进行diff。否则diff出来的patches就不正确了。

from simple-virtual-dom.

ibufu avatar ibufu commented on July 21, 2024

@livoras 我明白你的意思,但是这样构建DOM树确实有点点麻烦。。如果能支持判断循环的方法就好了

from simple-virtual-dom.

livoras avatar livoras commented on July 21, 2024

@ibufu 把构造虚拟DOM的操作封装成函数,每次状态改变就去调用这个函数重新构造就好了:https://github.com/livoras/simple-virtual-dom/blob/master/example/increasing-items.html#L20

from simple-virtual-dom.

livoras avatar livoras commented on July 21, 2024

有后续类似问题可以重开此issue :-)

from simple-virtual-dom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.