When the page loads and the user triggers an event, JavaScript starts a getJSON query and connects to the server JSON Brings the string. In this form:
[{id: 12, type: 'car', title: 'Ferrari'}, {ID: 17, type: 'bicycle', title: 'Ferrari'} ] So now I have this JSON string, now I'm a little bit stuck so this is how I would like to work it out:
In my page I have An input text is a search field in which the user can type the letters, and then Javascript will automatically find results from this JSO string, but only by title. It should not be searched by type or id. Then it should return as well as all IDs and types as JSON, after which I can pass the renderer which presents the elements inside the elements as inside of a div.
Part I is having problems with the actual search part. If I find the right results from searching then I know how to render them.
I have seen in full plugins, but I cant speak to them as I want and they really do not want to do such things, I agree. I like most of the plugins that are known for safe and error-free use. If you are saying that there is no good plugin for this, then I think I have to do this. I want to know before starting the wheel search again. The reason for searching on the client side is that I think it will be less pressure for the server, the reason is that it starts with all the results and the results have already been received, I do not want to need some results again because of its origin with AJAX, as long as the user does not make a certain event, it will not be received, which will be a button click.
PS: If you suggest how you will do it in the most effective way, feel free to educate me :)
You have to loop through the array and the title must match the search query you can match using substr () or indexOf () or using some cook with Regex . Just return the matches.
Small code example:
function autocomplete (search query, data) {var j = 0; Var returns = []; (In data) (if (data [i] .title.indexOf (searchquery)> 1) {returns [j ++] = data [i];}} return return;} It should start you, okay?
PS: Sorry, I did not know how to format the code above.
Comments
Post a Comment