简体   繁体   English

如何强制秘银重绘而不进行差异化? (在秘银中整合德拉古拉)

[英]How to force Mithril to redraw without diffing? (integrating dragula in Mithril)

I am translating a JQuery-based app to Mithril.我正在将一个基于 JQuery 的应用程序翻译成 Mithril。 That app uses Dragula to allow drag/drop to reorder lists.该应用程序使用 Dragula 允许拖放以重新排序列表。

  • Dragula reorders the li elements in the DOM. Dragula 对 DOM 中的li元素重新排序。
  • When the Drop event is fired, I sync the model and call m.redraw().当 Drop 事件触发时,我同步 model 并调用 m.redraw()。

However, the UI ends up in a mixed state:但是,UI 最终会出现混合的 state:

<li data-idx="0"> The Zero </li>
<li data-idx="1"> The One </li>

and after user dragging 1 before 0, it ends up as:并且在用户将 1 拖到 0 之前,它最终为:

<li data-idx="1"> The One</li>
<li data-idx="0"> The Zero</li>

Tried:试过:

  • m.redraw(), m.redraw.sync(), they correctly work but if ie. m.redraw(),m.redraw.sync(),它们可以正常工作,但如果即。 the LIs are moved by dragula, then the resulting HTML is in a mixed state. LI 由 Dragula 移动,然后生成的 HTML 位于混合 state 中。

  • clearing dom in vnode with the hope it would be recreated.清除vnode中的dom ,希望能重新创建它。

  • clearing vmode.dom.textContent清除vmode.dom.textContent
  • Assign random keys and IDs to the widget container, and to the different LIs将随机键和 ID 分配给小部件容器以及不同的 LI

... And nothing changes, either I get a blank widget or the values in "data-idx" are still wrong. ...并且没有任何变化,要么我得到一个空白小部件,要么“data-idx”中的值仍然错误。

So my question is, in general, is it possible, and how, to use these kind of libraries that manipulate a mithril widget inner html, and then call m.redraw() so mithril re-renders the mess?所以我的问题是,一般来说,是否有可能以及如何使用这些库来操作内部 html 的秘银小部件,然后调用 m.redraw() 以便秘银重新渲染混乱?

Background:背景:

  • Dragula is initialized in oncreate Dragula 在 oncreate 中初始化
  • My widgets are mounted with route:我的小部件安装有路线:

    "/videos": { “/视频”:{

     onmatch: () => loginWall(true), render: v => m(layoutWidget, m(videosWidget, v.attrs)) },

This is an older post but maybe you could provide more information about how the components are created in the videosWidget .这是一篇较旧的帖子,但也许您可以提供有关如何在videosWidget中创建组件的更多信息。 Mithril usually needs a key to distinguish between elements so that the current dom state is maintained as the model list changes as explained here: keys .秘银通常需要一个键来区分元素,以便在 model 列表更改时维护当前的 dom state,如下所述: keys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM