में परिणाम सीमित करें आप jQuery स्वत: पूर्ण से परिणाम पर सीमा कैसे निर्धारित कर सकते हैं?jQuery Autocomplete
यह मेरा कोड है:
$.ajax({
url: "/cache/search/SearchModels.xml",
dataType: "xml",
success: function(xmlResponse) {
var data = $("SearchModel", xmlResponse).map(function() {
return {
value: $("Name", this).text() + ", " + $("Description", this).text(),
id: $("No", this).text(),
name: $("Name", this).text(),
url: $("URL", this).text()
};
}).get();
$("#txtTopSearch").autocomplete({
source: data,
minLength: 2,
select: function(event, ui) {
BlockUI();
if (typeof (ui.item.url) != 'undefined') {
window.location = ui.item.url;
}
else {
alert('Page not found!');
$.unblockUI();
}
},
search: function(event, ui) {
$('#txtTopSearch').addClass('searchInProgress');
},
close: function(event, ui) {
$('#txtTopSearch').removeClass('searchInProgress');
}
}).data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a><span style='font-size:.9em; font-weight:bold;'>" + item.id + "</span><br /><span style='font-size:.8em;'>" + item.name + "</span></a>")
.appendTo(ul);
};
},
error: function(xhr, textStatus, errorThrown) {
alert('Error: ' + xhr.statusText);
}
});
इस कोड को वापसी क्वेरी में सभी परिणाम है, लेकिन मैं यह सिर्फ दिखाने के लिए 10 परिणामों को सीमित करना चाहते हैं। पुराने स्वत: पूर्ण संस्करण में इसके लिए एक विकल्प था, लेकिन अब इसे बहिष्कृत किया गया है। एक्सएमएल के
उदाहरण:
<?xml version="1.0"?>
<ArrayOfSearchModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SearchModel>
<No>1</No>
<Name>My product</Name>
<Description>My description</Description>
<Tags>blue;brown;</Tags>
<URL>/Products/1</URL>
</SearchModel>
</ArrayOfSearchModel>
सुझाव देने का वादा किया, लेकिन यह काम नहीं किया। ऐसा लगता है कि 'सर्चमोडेल' नियमित चयनकर्ता नहीं है। – Martin
@ मार्टिन, मुझे लगता है कि यह एक्सएमएल के अंदर इस्तेमाल किया जाने वाला एक टैग था। क्या आप XML फ़ाइल से कुछ सामग्री पोस्ट कर सकते हैं? मैं 'map' विधि –
का उपयोग करके वैकल्पिक समाधान पोस्ट करूंगा धन्यवाद, मैंने अपने प्रश्न को नोड के उदाहरण के साथ अपडेट किया है। – Martin