jQuery ajax 擷取資訊展示在“下拉式清單”中

來源:互聯網
上載者:User

標籤:i18n   dao   src   mapping   取整   擷取資訊   asc   ext   roc   

<link href="${ctxStatic}/jquery-select2/4.0.3/select2.min.css" rel="stylesheet" />
<script src="${ctxStatic}/jquery-select2/4.0.3/select2.full.min.js" type="text/javascript"></script>
<script src="${ctxStatic}/jquery-select2/4.0.3/i18n/zh-CN.js" type="text/javascript"></script>


$("[data-toggle=‘tooltip‘]").tooltip({html: true});
//擷取整個列表
$(‘#primaryAuditUserId‘).select2({
language: "zh-CN",
minimumInputLength: 1,
placeholder: "-- 請輸入暱稱搜尋 --",
ajax: {
url: "xxx/xxx/xxxx/userAll",
dataType: "json",
delay: 500,
data: function (params) {
return {name: params.term};//name為入參標識
},
processResults: function (res, params) {
var options = [];
console.log("res:"+res);
$(res).each(function (index, r) {
var option = {"id": r.id, "text": r.name};//列表中的id,列表中的name
options.push(option);
});
return {
results: options
};
},
escapeMarkup: function (m) {
return m;
}
}
});

//擷取ID
(function () {
var id = $("#select2-userId").val();
if (id) {
$.get("xxxxxx/xxxx/single/" + id, function (result) {
if (result) {
$("#primaryAuditUserId").html("<option value=‘" + result.id + "‘>" + result.name + "</option>");//
}
});
}
})();



<li>
<label>初審人:</label>
<input type="hidden" id="select2-userId" value="${infoDto.primaryAuditUserId}"/>
<form:select path="primaryAuditUserId" class="input-medium"></form:select>
</li>

 

介面:

//模糊比對列表
@RequestMapping(value="userAll")
@ResponseBody
public List<User> getUsers(String name){
User user=new User();
user.setDelFlag("0");
user.setName(name);
List<User> userList=userDao.findList(user);
if(userList.size()<=0||userList==null){
return null;
}
return userList;
}

//查詢單個的id
@RequestMapping(value="singUser")
@ResponseBody
public String getSingleUser(String name){
User user=new User();
user.setName(name);
User user_=userDao.getSingle(user);
return user_.getId();
}

jQuery ajax 擷取資訊展示在“下拉式清單”中

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.