Note that there are some explanatory texts on larger screens.

plurals
  1. POparsing json with jquery to populate datalist
    primarykey
    data
    text
    <p>I want to populate a datalist based on JSON data to create an autocomplete field.</p> <p>I have managed to get the following to work thanks to a <a href="http://www.raymondcamden.com/index.cfm/2012/6/14/Example-of-a-dynamic-HTML5-datalist-control" rel="nofollow">this tuotorial</a>:</p> <p>This json data:</p> <pre><code>{"COLUMNS":["ARTNAME"],"DATA":[["Morning Forest"],["Morph"],["Mountains"],["Mom"]]} </code></pre> <p>I can parse fine using this code: $(document).ready(function() {</p> <pre><code>if(document.createElement("datalist").options) { $("#search").on("input", function(e) { var val = $(this).val(); if(val === "") return; //You could use this to limit results //if(val.length &lt; 3) return; console.log(val); $.get("artservice.cfc?method=getart&amp;returnformat=json", {term:val}, function(res) { var dataList = $("#searchresults"); dataList.empty(); if(res.DATA.length) { for(var i=0, len=res.DATA.length; i&lt;len; i++) { var opt = $("&lt;option&gt;&lt;/option&gt;").attr("value", res.DATA[i][0]); dataList.append(opt); } } },"json"); }); } }) </code></pre> <p> </p> <p>and the autocomplete works as per the example I linked to.</p> <p>I am trying to parse this as my datasource:</p> <pre><code>{"responseHeader":{"status":0,"QTime":1,"params":{"q":"*a*","wt":"json"}},"response":{"numFound":2,"start":0,"docs":[{"id":"13","body":"Hi guys\r\n\r\nCould you please help me.\r\n\r\nCheers,\r\n\r\nTest Three","title":["Patience"],"_version_":1427207573191262208},{"id":"45","body":"Has been implemented!","title":["Validation"],"_version_":1427207573192310784}]}} </code></pre> <p>I am trying to get the 'Body' to auto-complete in the datalist. I'm not sure how to get it to work with this more complex json data.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload