久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Jquery Chosen 插件 - 通過 Ajax 動態填充列表

Jquery Chosen plugin - dynamically populate list by Ajax(Jquery Chosen 插件 - 通過 Ajax 動態填充列表)
本文介紹了Jquery Chosen 插件 - 通過 Ajax 動態填充列表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用為 Multiple Select 選擇的插件構建我的下拉菜單.這是我基于的行為:

Im trying to build my dropdown menu using the plugin Chosen for Multiple Select . Here's to behavior I'm based on:

http://jsfiddle.net/JfLvA/

所以,而不是 3 硬編碼 <選項 > 在我的選擇中.我希望這個列表是由 ajax 請求填充的 json 數組的值.這將由自動完成觸發.

So, instead of having 3 harcoded < option > in my select. I want this list to be the values of a json array populated by an ajax request. This will be triggered by autocomplete.

所以,如果用戶鍵入汽車",我會通過 ajax 調用發送這封信,然后我會返回一個這樣的數組:

So, if the user type "car", im sending the letter via an ajax call, and im getting back an array like that:

[{"id":"2489","name":"carrie"},{"id":"2490","name":"Caroline"},{"id":"2491","name":"Carole"}]

[{"id":"2489","name":"carrie"},{"id":"2490","name":"Caroline"},{"id":"2491","name":"Carole"}]

代碼:

$(function() {

$(".chzn-select").chosen();
$(".chzn-select-deselect").chosen({allow_single_deselect:true});

$('.chzn-choices input').autocomplete({
   source: function( request, response ) {
      $.ajax({
          url: "/change/name/autocomplete/"+request.term+"/",
          dataType: "json",
          success: function( data ) {
             response( $.map( data, function( item ) {
                $('ul.chzn-results').append('<li class="active-result">' + item.name + '</li>');

          }
       });
    }
});

結果:

我在下拉列表中輸入汽車",然后得到汽車沒有結果",然后我就得到了所有結果,如我所愿.

I type "car", in the dropdown Im getting "No result for car" and then I have all my results, as I want.

1.為什么我會收到無結果"消息,因為我可以在我的 json 數組和列表中看到我正在獲得結果.

 -----------------------------

當我刪除car"并輸入sam"時.sam"的結果顯示在car"結果之后.(基本上,我看到了兩者的結果,而不僅僅是我當前搜索的結果)

When I delete "car" and enter "sam". The results for "sam" are showing after the "car" results. (Basically, I see the result for both, instead of just having the result of my current search)

<強>2.我想清除 keyUp 上的 ul 嗎?以為插件已經這樣做了

 -----------------------------

當我單擊一個名稱以實際選擇它并將其添加到選擇中時,我在 selected.js 文件中收到一個 javascript 錯誤

When I click on a name to actually select it and add it into the select, Im getting a javascript error inside the chosen.js file

項目未定義
item.selected =真;"第732行

item is undefined
"item.selected = true;" line 732

插件鏈接:http://harvesthq.github.com/chosen/chosen/chosen.jquery.js

它沒有在選擇中添加任何內容.

and it's not adding anything inside the select.

3.不知道為什么會這樣

 -----------------------------

你們知道我做錯了什么嗎?我完全被困在這里......!

Do you guys have any idea on what I'm I doing something wrong? I'm completly stuck here...!

哦,順便說一句,我不介意更改插件源,因為它是我唯一使用它的地方......

Oh and by the way, I dont mind changing the plugin source, as it's the only place where I'm using it....

推薦答案

試試這個:

$('.chzn-choices input').autocomplete({
  source: function( request, response ) {
    $.ajax({
      url: "/change/name/autocomplete/"+request.term+"/",
      dataType: "json",
      beforeSend: function(){$('ul.chzn-results').empty();},
      success: function( data ) {
        response( $.map( data, function( item ) {
          $('ul.chzn-results').append('<li class="active-result">' + item.name + '</li>');
        }));
      }
    });
  }
});

這篇關于Jquery Chosen 插件 - 通過 Ajax 動態填充列表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 色欧美片视频在线观看 | 四虎影音 | 天天澡天天狠天天天做 | 精品久久久久久亚洲精品 | 人人人艹 | 国产精品资源在线 | 国产高清视频一区 | 在线国产小视频 | 国产一区二区精品在线观看 | 日本午夜视频 | 性国产丰满麻豆videosex | 蜜臀久久99精品久久久久久宅男 | 成年人黄色免费视频 | 中文字幕的av | 蜜桃视频在线观看免费视频网站www | 综合久久av | 欧美日韩午夜精品 | 波多野结衣一区二区 | 欧美一区二区三区在线看 | 51ⅴ精品国产91久久久久久 | 精品国产乱码久久久久久影片 | 亚洲不卡一| 777zyz色资源站在线观看 | 亚洲欧洲一区 | 亚洲成人精品一区 | 久久精品亚洲成在人线av网址 | 国产自产21区 | 色永久 | 亚洲三区视频 | 久久久国产精品视频 | 日韩一区二区三区在线视频 | 成人国产精品久久久 | 亚洲精品久久久久久国产精华液 | 好姑娘影视在线观看高清 | 午夜一级黄色片 | 午夜一级大片 | 色.com| 先锋资源网 | 亚洲欧美中文日韩在线v日本 | 国产免费又色又爽又黄在线观看 | 欧美激情精品久久久久久免费 |