Suppose there is a json file with similar lines:

[ { "code":"XIY", "name":"Xianyang", "coordinates":{ "lon":108.75605, "lat":34.441154 }, "time_zone":"Asia/Shanghai", "name_translations":{ "de":"Xian Xianyang", "en":"Xianyang", "zh-CN":"西安咸阳机场", "tr":"Xi'an Xianyang Havalimanı", "ru":"Синьян", "it":"Xianyang", "fr":"Xianyang", "es":"Xianyang", "th":"ท่าอากาศยานนานาชาติซีอานเสียนหยาง" }, "country_code":"CN", "city_code":"SIA" } ] 

Suppose that there are many such lines. In such a json file, I need to perform a search: I want to find all the arrays in which the country_code value is equal to CN and pull the value of the name field from the appropriate search condition arrays. For such a task on the server side of my application, I use a recursive array search:

 function recursive_array_search($needle,$haystack) { foreach($haystack as $key=>$value) { $current_key=$key; if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) return $current_key; } return false; } 

But in this case, the search will be performed more than once when the page is loaded, but as much as the user wants and this is critical for the server’s computing resources. In this regard, I decided to shift this task to jQuery.

Question: Is it possible to perform recursive search on jQuery directly from the json string? Or does it work differently on JS?

  • jQuery as if for DOM manipulations coined by vaschet - Jean-Claude
  • @ Jean-Claude vaschet now I have everything set up in such a way that json-perfectly displayed and sorted using JS. The problem is that when you load the page displays a lot of elements and the page terribly slow. I just need to make a dynamic system for searching and outputting the requested values ​​so that the page is initially empty, but when choosing filters from the json string, the desired values ​​were selected. - JamesJGoodwin
  • so why not iterate through the array to find a CN like this jsbin.com/tiziquwini/edit?html,console ? - Jean-Claude
  • @ Jean-Claude is interesting, but will I be able to store a json string in a 2.7mb variable? : D - JamesJGoodwin
  • just in case: if, for example, a huge table is displayed, then setting the width of the fixed columns greatly increases the browser rendering speed. - teran

0