Insert into HTML select tag options from a JSON

前端 未结 6 1789
甜味超标
甜味超标 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 15:11

    most immediately you need to change this:

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

    To this:

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

    That's just a key to get to the data, so make sure you use the same key.

    There may be some difficulty in rendering:

    value="1"
    

    As you are depending id="{$CODE}" to translate to that, which it will not do automatically.

    Good luck!

提交回复
热议问题