I've got a JSON file with a list of items. Each item has an ID and a name such as
{ID : 11, Name: 'item 1'}
I'm using the jQuery Mobile framework where I need to put a textbox where users can start typing an item name and the list should populate items from the file with the letters inside (some sort of autocomplete).
BTW - the list is VERY long (thousands of items) so I wouldn't like to load it all at once.
Any ideas how this can be accomplished?
Thanks!
I would create a function to return the result set based upon the "terms" in the phrase entry.
An example would be to use the source: of the jQuery UI Autocomplete and then filter your json data (cached on load?) based on the occurence. Something similar to breaking the phrase with a string split and iterating over that like with jQuery(':contains(text)') comes to mind.
If your json is an array jQuery.grep() might be perfectly suited. http://api.jquery.com/jQuery.grep
Here is another example in this question: How can I "filter" JSON for unique key name/value pairs?
Couple of other options in the answers here: json jquery filter javascript array
Related
I did a search on this topic and I am not that JSON familiar, so I thought I'd see if I can find the answer here to my question from the community.
I have a view from a list that I am formatting in SharePoint (SP) that creates some automated JSON. It simply colors the items based on if the value matches in the generated JSON code. I am trying to tweak it but having trouble getting the format to come up as a match.
I am trying to use just the one column called Display. It's a calculated field which concatenates a bunch of string text.
Here is what the generated section of code from SP I am trying to tweak looks like (this is not all of it):
{ "operator": "==",
"operands": [
"[$Display]",
"LOCATED"
]
}, =if(#isSelected == "true" etc...
So the formatting will happen if the data in field Display = LOCATED returning true and will apply the formatting. What I am trying to do, is get some sort of string contains or wild card matching.
The contents of the field Display in the SP list will contain something dynamic and possibly the word LOCATED somewhere in the text.
So ideally I'd like to tweak this code to return true for the formatting if the Display field content said something like "John Doe LOCATED New York" for example.
if anyone has any ideas how I could solve this that would be great. Also I was trying another field which is a choice field for exact matching but I couldn't get it to work either.
Thanks.
This issue has been resolved, by doing an exact field match instead of wildcarding.
Can I populate a list with JSON data? I have a general list containing data available for several sessions but I need to filter them with my current session and insert them to another list. My idea is to use the filtered JSON data since I successfully filtered them in JSON format. I've looked into some threads that might relate but currently get nothing. Hope someone can point me to the right page.
I missed this page: or maybe I overlooked it: https://forum.alphasoftware.com/showthread.php?119524-How-to-populate-a-List-from-a-JSON-formatted-field.
Anyway, populating JSON data into list in alpha anywhere is easy to be done. Firstly, get the JSON data(in my case I produce them from another list). With this data(already in JSON format), I do the filter using:
var filtered_json = find_in_object(JSON.parse('my_JSON_data'), {my_filter_condition});
Then, the result should be in [object object][object object]
Finally, populate the result to the list.
var lObj= {dialog.object}.getControl('my_list_ID')
lObj.populate(filtered_json);
I use the json_data plugin of jsTree.
When I call:
$("#my_tree").jstree('get_json');
the function returns only the JSON data of the currently selected node.
If nothing is selected, then I can get the entire data and that's ok, but if a leaf is selected I only get the JSON part corresponding to the leaf.
What is the way to get always the JSON of the entire jstree?
PS: I don't want to manually deselect the currently selected node. That would be a dirty trick.
Like suggested in the comments I've tried:
$("#my_tree").jstree('get_json', -1);
and that works just fine.
I have a google chart and want to add a custom tooltip. I found some great answers like this this site and set about doing this with roles. I also found this link about it and it looked like the best way.
My data is being generated via json and I use a php file to create a json feed. The rows I have coded like this
{"cols": [ {"id":"","label":"Period","pattern":""},
{"id":"","label":"Recorded P/L","type":"number", "role":"data"} ,
{"id":"","label": null,"type":"string", "role":"tooltip"},
{"id":"","label":"Best Available P/L","type":"number", "role":"data"},
{"id":"","label": null,"type":"string", "role":"tooltip"}
]
Then it goes on and adds all the data. The problem is when I try to run this I get the error
All series on a given axis must be of the same data type
I have checked the json and that is formed correctly but am not sure what I could be doing wrong.
At least part of your problem is that you're not specifying the type for your first column.
I've two fields with the same name name="s[]", but this creates an array, I don't need an array instead I'd like to construct a string.
I'm using these fields to submit search query to wordpress, if I will use an array I will have to mess with wordpress core, which I don't want. So my only option is to create 1 single string from two fields and submit it to query.
What do you think?
I think there are two options:
Submit the form to a different page, which redirects to the normal WordPress search page
Catch the onSubmit event using JavaScript and rewrite / add to the form data
I would prefer option 1 because it will work for browsers that don't use JavaScript. If you go with option 2, then you should not even show your two-field search interface to browsers that don't have JavaScript.