Insert into HTML select tag options from a JSON

前端 未结 6 994
南方客
南方客 2021-02-09 14:32

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:56

    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);
    

提交回复
热议问题