Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery模板中访问json文件_Json_Jquery - Fatal编程技术网

在jquery模板中访问json文件

在jquery模板中访问json文件,json,jquery,Json,Jquery,我希望json在json文件中,并希望在jquery模板中访问。我如何才能做到这一点呢 var movies = [ { Name: "The Red Violin", ReleaseYear: "1998" }, { Name: "Eyes Wide Shut", ReleaseYear: "1999" }, { Name: "The Inheritance", ReleaseYear: "1976" } ]; var markup = "<li><b>

我希望json在json文件中,并希望在jquery模板中访问。我如何才能做到这一点呢

var movies = [
  { Name: "The Red Violin", ReleaseYear: "1998" },
  { Name: "Eyes Wide Shut", ReleaseYear: "1999" },
  { Name: "The Inheritance", ReleaseYear: "1976" }
  ];

var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>";

/* Compile the markup as a named template */
$.template( "movieTemplate", markup );

/* Render the template with the movies data and insert
   the rendered HTML under the "movieList" element */
$.tmpl( "movieTemplate", movies )
  .appendTo( "#movieList" );
}))

要访问字段,但显示为数据[0]的错误未定义

用于加载json文件内容:

var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>";

/* Compile the markup as a named template */
$.template( "movieTemplate", markup );

$.getJSON('movies.json', function(data) {

  // 'data' is the json loaded and parsed from the file
  $.tmpl( "movieTemplate", data )
     .appendTo( "#movieList" );

});
var-markup=“
  • ${Name}(${ReleaseYear})
  • ”; /*将标记编译为命名模板*/ $.template(“movieTemplate”,标记); $.getJSON('movies.json',函数(数据){ //“data”是从文件中加载和解析的json $.tmpl(“movieTemplate”,数据) .附于(“#movieList”); });
    我想从json文件中访问名称字段。。。您能帮我找出
    数据[0]吗?Name
    将为您提供数组中第一个元素的属性名的值。
    var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>";
    
    /* Compile the markup as a named template */
    $.template( "movieTemplate", markup );
    
    $.getJSON('movies.json', function(data) {
    
      // 'data' is the json loaded and parsed from the file
      $.tmpl( "movieTemplate", data )
         .appendTo( "#movieList" );
    
    });