使用foreach循环出json数据

var moviesData = [
    {
        "title" : "Inside Out",
        "summary" : "An emotional adventure inside the head of a young girl."
    },
    {
        "title" : "Tomorrowland",
        "summary" : "Recreating the hope and wonder of previous generations."
    },
    {
        "title" : "The Wizard of Oz",
        "summary" : "Strangers find friendship and strength on a long walk."
    }
];

function getMovieHTML (movie) {
    var html = "

" + movie.title + "

"; html += "

" + movie.summary + "

"; return html; } function getMoviesHTML (movies) { var html = ""; movies.forEach(function (movie) { html += "
  • " + getMovieHTML(movie) + "
  • "; }); return "
      " + html + "
    "; } function render (movies) { var moviesDiv = document.getElementById("movies"); moviesDiv.innerHTML = getMoviesHTML(movies); } render(moviesData);

     

    你可能感兴趣的:(js)