在jloq中使用ClojureScript中的jquery-ui

jwh*_*ark 4 jquery-ui clojurescript

我正在尝试使用jayq和jquery.ui.sortable来对页面进行排序.看看http://jqueryui.com/demos/sortable/看起来它应该像下面这样简单:

(.sortable ($ :#sortable))
Run Code Online (Sandbox Code Playgroud)

其中编译为:

jayq.core.$.call(null, "\ufdd0'#sortable").sortable();
Run Code Online (Sandbox Code Playgroud)

并抛出:

Uncaught TypeError: Cannot call method 'call' of undefined
Run Code Online (Sandbox Code Playgroud)

当我尝试将其包含在页面中时.有趣的是,当我将它粘贴到js控制台时,生成的代码在页面中起作用,这意味着在执行该行之后会加载必要的东西.

我修改了

(def cljs-options {:advanced {:externs ["externs/jquery.js"]}})
Run Code Online (Sandbox Code Playgroud)

(def cljs-options {:advanced {:externs ["externs/jquery.js" "js/ui/jquery-ui.js]}})
Run Code Online (Sandbox Code Playgroud)

在阅读 http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html之后 ,这似乎不够.我猜jquery.ui会修改$ Prototype,但我不知道如何在clojurescript中完成此操作

我也使用黑色和黑色 - 如果它有任何区别.

看看使用jQueryUI和闭包编译器, 它可能只是jquery-ui需要一个手动滚动的externs文件才能被使用,这可能是一项重大任务.谁能确认一下?

jwh*_*ark 6

解决这个问题有两个不同的方面.

  1. 要在高级模式下编译,我需要将以下内容添加到我的externs文件中.

    $.prototype.sortable = function (a,b) { };
    $.prototype.disableSelection = function (a,b) { };
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我正在使用noir-cljs,在我的视图模板中,有以下内容:

    (:require [noir.cljs.core :as cljs])
    (:use [hiccup.page :only [include-js]])
    ...
    (cljs/include-scripts :with-jquery)  
    (include-js "/js/jquery-ui.js")
    
    Run Code Online (Sandbox Code Playgroud)

但这无法工作,因为jquery-ui代码需要在jquery之后但在生成的ClojureScript之前包含.解决方案是在页面中手动包含库:

(include-js "/js/jquery.js")
(include-js "/js/jquery-ui.js")
(include-js "/cljs/bootstrap.js") ;; Generated
Run Code Online (Sandbox Code Playgroud)