Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
BackboneJS HandlebarsJS显示来自Spotify JSON的JSON_Json_Backbone.js_Handlebars.js_Spotify - Fatal编程技术网

BackboneJS HandlebarsJS显示来自Spotify JSON的JSON

BackboneJS HandlebarsJS显示来自Spotify JSON的JSON,json,backbone.js,handlebars.js,spotify,Json,Backbone.js,Handlebars.js,Spotify,我想使用Spotifys API在我的主干视图上显示相关的艺术家。到目前为止还不错,我设法加载了API/JSON数据,但我还不能在我的Handlebar模板中显示它,我得到了一个空的HTML模板,我不知道我做错了什么 以下是我的主要收藏: ArtistRelated.Collection = Backbone.Collection.extend({ url: function() { return 'https://api.spotify.com/v1/artists/1

我想使用Spotifys API在我的主干视图上显示相关的艺术家。到目前为止还不错,我设法加载了API/JSON数据,但我还不能在我的Handlebar模板中显示它,我得到了一个空的HTML模板,我不知道我做错了什么

以下是我的主要收藏:

ArtistRelated.Collection = Backbone.Collection.extend({
    url: function() {
        return 'https://api.spotify.com/v1/artists/1HY2Jd0NmPuamShAr6KMms/related-artists';
    },      
    parse: function(artists){
        return artists;
    }           
});
和我的车把HTML:

{{#each this}}
  <img src="{{images.url}}" alt="{{name}}">
  <div>
   <h3>{{name}}</h3>
  </div>
{{/each}}
{{{#每个this}
{{name}}
{{/每个}}
我以API为例:

我做错了什么?

好的,我自己解决了:

将集合的解析方法添加/更改为:

parse: function(response){
    return response.artists;
}
和把手模板:

{{#each this}}
 <img src="{{this.images.[0].url}}" alt="{{this.name}}">
 <div>
   <h3>{{this.name}}</h3>
 </div>
{{/each}}
{{{#每个this}
{{this.name}}
{{/每个}}

它现在起作用了!:-)

重要的是,视图中的渲染方法是什么样子的?