Using jQuery UI functions with Mithril

纵饮孤独 提交于 2019-12-12 16:26:51

问题


I am new to the Mithril JS framework and I love its rendering performance. It being light-weight is a plus, but I would like to use jQuery UI so that I can benefit from some of its functionality such as the draggable interaction. From my understanding, both jQuery UI and Mithril manipulate DOM elements. If so, how practical is it to use jQuery UI with Mithril?


回答1:


Your question is a bit open ended, but to give a useful answer: Mithril templates don't actually touch the DOM until you call either m.render, m.module or m.route. When you do, the diff engine creates or updates elements as needed to mirror the structure of the template. You can use config in templates to get to real DOM elements, and run jQuery/jQuery UI on them:

function draggable(element, isInitialized) {
  if (!isInitialized) $(element).draggable()
}

var module = {}
module.controller = function() {
  this.greeting = "Hello"
}
module.view = function(ctrl) {
  m("div", {config: draggable}, ctrl.greeting)
}

m.module(document.body, module)


来源:https://stackoverflow.com/questions/25862728/using-jquery-ui-functions-with-mithril

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!