jqueryを使用して検索候補ボックスまたは自動完成ボックスを作成する方法と戦っていますが、これはまだ動作していません。Clojure:Clojure/CompojureでJqueryを使用して検索候補機能を実装する方法
私routes.homeで私はget-client-list
出力からの出力としての私のlist
を見ることができ、以下の持っているが{:id 2, :name "foobar"}
(defn get-list! [{:keys [params]}]
(log/infof "Pulling client list from db" params)
(let [list (into {} (db/get-client-list params))]
;;list is like hugsql
(log/infof "List of names -> [%s]" list)
(if (empty? list)
(log/errorf "No record found [%s]" list)
(do
(log/infof "The list is ->[%s]" list)
;; seems am missing something here, dont know
;;code for readlist.html is still far below
(layout/render "readlist.html" (:records list))))))
(defn about-page [{:keys [flash]}]
(layout/render "home.html"
(merge nil (select-keys flash [:name :amount :value :er :errors]))))
(defroutes home-routes
(GET "/getinfo" {:keys [headers params body] :as request}
(do
(if (empty? (:user (:session request)))
(do
(log/info "Unauthorised attempt to /getinfo URL:" request)
(response/found "/"))
(about-page request))))
(POST "/getinfo" request
(if (empty? (:user (:session request)))
(do
(log/info "Unauthorised attempt to /getinfo URL:" request)
(response/found "/"))
(msg! request)))
(GET "/clientlist" request (get-list! request)))
マイhome.htmlのようなものです
私base.htmlでその後3210、 iはreadlist.htmlコードが
{% for item in records %}
<li onClick="selectList('{{item.name|join}}');">
{{item.name|join}}
</li>
{% endfor %}
アシストしてください下にある
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#search-box").keyup(function(){
$.ajax({
type: "GET",
//calling this URL in route.home
// why are you not working?
url: "/clientlist",
data:'keyword='+$(this).val(),
beforeSend: function(){
$("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
},
success: function(data){
$("#suggestion-box").show();
$("#suggestion-box").html(data);
$("#search-box").css("background","#FFF");
}
});
});
});
function selectList(val) {
$("#search-box").val(val);
$("#suggestion-box").hide();
}
</script>
が<head>
以内にこのスクリプトを置き、それを理解しようとしている時間を費やし。 ありがとう
ありがとうございました – user7764270