js-jquery-autocomplete获取当前正在输入input的值 (input focus) 或者 根据此input获取其他dom对象
console.log($("input:focus").parents("tr").find("input[name='idStuff']").val());
背景 需要在 jquery的autocomplete 自动填充的同时 获取 input 兄弟节点的 某个 dom节点的 值
思路:通过input:focus 来找到当前行对向
function stuffAutoComplete(item){
$(item).autocomplete({
html: true,
source: autocompleteSourceFunction,
select: autocompleteSelectFunction
});
}
//材料提示
var autocompleteSourceFunction = function (request, response) {
console.log($("input:focus").parents("tr").find("input[name='idStuff']").val())
var customerInfo = f6car.maintainProtoType.getCustomerInfo(),
mainId = $('#carModelChooseInput').find('input[name=mainId]').val(),
data = {
featureClass: "P",
style: "full",
maxRows: 12,
nameStandard: request.term,
//carCategoryId: $("#carCategoryId").val(),
sorts: {orderField: "s.stock_number", orderType: "DESC"},
mid: (customerInfo && customerInfo.mainId) ? customerInfo.mainId : (mainId ? mainId : null)
},
adaptIcon = '<img src="/images/adapt.png" class="adapt-icon adapt-icon--fit"/>',
notAdaptIcon = '<img src="" class="adapt-icon adapt-icon--not-fit"/>';
if ($("#viewType").val() === 'GDCRK' && $('#balanceStatus').val() !== '7000') {
data.isLocal = 1;
}
//根据材料价格分类来的,这两种情况的id都传给carCategoryId,后端实现根据配置表去处理
if(isUsePriceChannelId4StuffPrice()){
data.carCategoryId = $("#priceChannelIdDom").val()
}else {
data.carCategoryId = $("#carCategoryId").val()
}
$.ajax({
url: stuffTipUrl,
dataType: "json",
type: "post",
contentType: "application/json",
data: JSON.stringify(data),
success: function (data) {
if (request.term != "" && data.length == 0) {
Messenger({
extraClasses: 'messenger-fixed messenger-on-top'
}).post({
message: '没有搜索到结果',
type: 'error',
hideAfter: 1
});
}
response($.map(data, function (item) {
//注意: 车辆分类价格和渠道分类价格都在partCategoryAmountVoList节点中。
partInfoSellPrices[item.pkId] = item.partCategoryAmountVoList;
var stockNumStr = "";
if (parseFloat(item.stockNumber) >= 0) {
stockNumStr = " 现有库存数:" + item.stockNumber
}
item.name = escapeHtml(item.name);
item.showName = escapeHtml(item.showName);
return {
label: (item.adaptFlag ? adaptIcon : notAdaptIcon) + item.showName + " " + stockNumStr,
value: item.name,
result: item
}
}));
}
});
};
正文到此结束
- 本文标签: JavaScript
- 本文链接: https://code.jiangjiesheng.cn/article/97
- 版权声明: 本文由小江同学原创发布,转载请先联系本站长,谢谢。