Insert into HTML select tag options from a JSON

前端 未结 6 1790
甜味超标
甜味超标 2021-02-09 14:18

So, here\'s the deal: I have a JSON object saved in my web App at localStorage. This JSON is being saved as a string, with JSON.stringify, inside one of my function

6条回答
  •  [愿得一人]
    2021-02-09 14:49

    to answer the actual question on how to do this in json2html .. with the correct transform

    var jsonData = $.parseJSON(window.localStorage.getItem("data"));
    var transform = {tag:'option', id:'${CODE}',html:'${NAMEVAR}'};
    document.getElementById('mySelectID').innerHtml = json2html.transform(jsonData,transform);
    

    OR using the jquery plugin for json2html

    var jsonData = $.parseJSON(window.localStorage.getItem("data"));
    var transform = {tag:'option', id:'${CODE}',html:'${NAMEVAR}'};
    $('#mySelectID').json2html(jsonData,transform);
    

提交回复
热议问题