JQuery移动端和Scala.js:如何调用"navbar()"或"toolbar()"等函数?

JQuery Mobile and Scala.js: How to call functions like "navbar()" or "toolbar()"?

在 JQuery 移动设备中,要使持久的页眉、页脚和 nabbers 按预期工作,您必须执行以下操作:

$(function() {
    $( "[data-role='navbar']" ).navbar();
    $( "[data-role='header'], [data-role='footer']" ).toolbar();
});

Scala.js 中的等价物是什么?

像在 Scala.js 中一样,作为第一个 "draft",您始终可以使用动态类型 API:

js.Dynamic.global.$("[data-role='navbar']").navbar()

如果你想要一个静态类型API,你可以定义它。据我所知,还没有人为 jQuery 移动设备编写外观类型。不过,jQuery本身也有门面,比如1. You can then "pimp" additional methods provided by a jQuery plugin, such as jQuery mobile, using the monkey patching pattern for Scala.js facades:

import org.querky.jquery._

trait JQueryMobile extends JQuery {
  def navbar(): Unit
}

implicit def JQueryMobileOps(jQ: JQuery): JQueryMobile =
  jQ.asInstanceOf[JQueryMobile]

然后你可以做:

$("[data-role='navbar']").navbar()

并且会进行静态类型检查。