我正在jquery自动完成中检索一些多列数据。一切正常,但问题是自动完成只显示那些不包含浮点值或双精度值的值。例如,如果产品名称是jquery 2.0,那么它只检索(或显示)jquery 2 我尝试格式化我的网络服务查询
select format(ProductName , '0.00') as ProductName, ProductCode, format(Mrp,'0.00') as Mrp,PackingName,format(SaleRate,'0.00') as SalesRate ,SchemeRatio from ProductMaster where " & "ProductName like @SearchText + '%'
但它没有改变任何东西。 我需要做些什么改变,请帮助,提前致谢!
这是我的jquery代码
<script type ="text/javascript">
$(document).ready(function () {
$("#<%#txtSearch.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%#ResolveUrl("~/Service.asmx/GetCustomers") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
var safe = data
response($.map(safe.d, function (item) {
return {
label: item.split('.')[0],
value: item.split('-')[0]
}
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$("#<%#hfProductId.ClientID %>").val(i.item.value);
},
minLength: 1,
});
$("#<%#txtSearch.ClientID %>").autocomplete().data("ui-autocomplete")._renderItem = function (ul, item) {
var line_item = '';
line_item += "<a><div class='search_row'>";
line_item += "<div class='sku'>Product Name- " + item.label.split('-')[0] + "</div>" + "<div class='productcode'>Product Code- " + item.label.split('-')[1] + "</div>" + "<div class='sku'>Product Mrp- " + item.label.split('-')[2] + "</div>" + "<div class='sku'>Packing Name- " + item.label.split('-')[3] + "</div>" + "<div class='sku'>Scheme Ratio- " + item.label.split('-')[4] + "</div>";
line_item += "<hr>";
line_item += "</div></a>";
return $("<li>")
.append(line_item)
.appendTo(ul);
};
});
</script>
答案 0 :(得分:0)
我认为您需要在jquery端应用该函数..
例如
parseFloat(yourValue).toFixed(2)
答案 1 :(得分:0)
response($.map(safe.d, function (item) {
return {
label: item.split('.')[0],
value: item.split('-')[0]
}
到
response($.map(safe.d, function (item) {
return {
label: item.split('^')[0],
value: item.split('-')[0]
}
它有效。