Insert into HTML select tag options from a JSON

前端 未结 6 992
南方客
南方客 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:49

    I think there are a couple of errors in your code. Try this instead:

    // it's class, not id, and no fullstop required.
    // The $ sign was in the wrong place.
    var transform = {tag:'option', class:'$(CODE)', html:'${NAMEVAR}'};
    
    // it's innerHTML not innerHtml
    document.getElementById('mySelectID').innerHTML = json2html.transform(jsonData, transform);
    

提交回复
热议问题