数据未存储在变量中

时间:2015-10-25 16:22:15

标签: javascript

我正在尝试将数据添加到空var中,但数据未被存储。 致电web.xml时,它显示为空。我错过了什么?谢谢!

...
<context-param>
<param-name>resteasy.role.based.security</param-name>
<param-value>true</param-value>
</context-param>
...

1 个答案:

答案 0 :(得分:1)

&#13;
&#13;
var data = '[{"name": "h1"}, {"name": "h2"}]';
var hotelData = JSON.parse(data);

function hotelList(){
    var hotel_list = '';
    (hotelData || []).forEach(function (hotel, index) {
            hotel_list += '<li class="hotel" data-index="'+ index +'">'+ hotel.name +'</li>';
        });
     document.getElementById("hotel-listing").innerHTML = hotel_list;
};

document.addEventListener('DOMContentLoaded', function() {
    hotelList();
});
&#13;
<div id="hotel-listing"></div>
&#13;
&#13;
&#13;