将jQuery UI函数与Mithril结合使用 [英] Using jQuery UI functions with Mithril

查看:108
本文介绍了将jQuery UI函数与Mithril结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Mithril JS框架的新手,我喜欢它的渲染性能.轻巧是一个加号,但我想使用jQuery UI,以便可以从其某些功能(例如可拖动的交互)中受益.据我了解,jQuery UI和Mithril都可以操作DOM元素.如果是这样,将jQuery UI与Mithril一起使用有多实用?

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?

推荐答案

您的问题有点悬而未决,但要给出一个有用的答案:秘银模板实际上不会触及DOM,直到您调用m.renderm.modulem.route.完成后,差异引擎会根据需要创建或更新元素以镜像模板的结构.您可以在模板中使用config来获取真实的DOM元素,并在其上运行jQuery/jQuery UI:

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)

这篇关于将jQuery UI函数与Mithril结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆