How to search JSON tree with jQuery

var json = { “people”: { “person”: [{ “name”: “Peter”, “age”: 43, “sex”: “male”}, { “name”: “Zara”, “age”: 65, “sex”: “female”}] } }; $.each(json.people.person, function(i, v) { if (v.name == “Peter”) { alert(v.age); return; } }); Example. Based on this answer, you could use something like: $(function() { var json = { “people”: { “person”: … Read more

JS search in object values

Something like this: var objects = [ { “foo” : “bar”, “bar” : “sit” }, { “foo” : “lorem”, “bar” : “ipsum” }, { “foo” : “dolor”, “bar” : “amet” } ]; var results = []; var toSearch = “lo”; for(var i=0; i<objects.length; i++) { for(key in objects[i]) { if(objects[i][key].indexOf(toSearch)!=-1) { results.push(objects[i]); } } } … Read more

Expand and give focus to SearchView automatically

You can also call to expandActionView() method in order to force it: @Override public boolean onCreateOptionsMenu( Menu menu ) { super.onCreateOptionsMenu( menu ); MenuItem searchMenuItem = menu.findItem( R.id.mi_search ); // get my MenuItem with placeholder submenu searchMenuItem.expandActionView(); // Expand the search menu item in order to show by default the query return true; } Search … Read more

Trigger an action after selection select2

See the documentation events section Depending on the version, one of the snippets below should give you the event you want, alternatively just replace “select2-selecting” with “change”. Version 4.0 + Events are now in format: select2:selecting (instead of select2-selecting) Thanks to snakey for the notification that this has changed as of 4.0 $(‘#yourselect’).on(“select2:selecting”, function(e) { … Read more

using OR and NOT in solr query

I don’t know why that doesn’t work, but this one is logically equivalent and it does work: -(myField:superneat AND -myOtherField:somethingElse) Maybe it has something to do with defining the same field twice in the query… Try asking in the solr-user group, then post back here the final answer!

In Python, how to check if a string only contains certain characters?

Here’s a simple, pure-Python implementation. It should be used when performance is not critical (included for future Googlers). import string allowed = set(string.ascii_lowercase + string.digits + ‘.’) def check(test_str): set(test_str) <= allowed Regarding performance, iteration will probably be the fastest method. Regexes have to iterate through a state machine, and the set equality solution has … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)