-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
用push的方法往一个已创建的Element里插入childern,不能自动更新Element的count #4
Comments
@ibufu 一般情况下是不会直接操作Element的children的,Element应该在每次状态变更的时候重新构造。不知道你的问题具体是什么,能否提供一下具体代码呢? |
@livoras 建好了一个Element后,需要做增删改,所以要往element的children里push,或者根据我设置的id遍历children修改数据。(因为只是很局部的操作)操作起来很麻烦,而且push的时候,还要更新count,不然diff的时候index就会出错。 |
@livoras 如果能开一个方便修改element的接口就好了 |
@ibufu 即使是非常小的局部修改,也应该重新构造整棵虚拟DOM。一个虚拟DOM树一旦构造就不应该手动修改,它只是保存目前DOM树的状态。状态变更就应该构造新的树,再和原来的树进行diff。否则diff出来的patches就不正确了。 |
@livoras 我明白你的意思,但是这样构建DOM树确实有点点麻烦。。如果能支持判断循环的方法就好了 |
@ibufu 把构造虚拟DOM的操作封装成函数,每次状态改变就去调用这个函数重新构造就好了:https://github.com/livoras/simple-virtual-dom/blob/master/example/increasing-items.html#L20 |
有后续类似问题可以重开此issue :-) |
每次增加删除childern,都要手动重新计算Element的count,很麻烦
The text was updated successfully, but these errors were encountered: