BackboneJS HandlebarsJS显示来自Spotify JSON的JSON
我想使用Spotifys API在我的主干视图上显示相关的艺术家。到目前为止还不错,我设法加载了API/JSON数据,但我还不能在我的Handlebar模板中显示它,我得到了一个空的HTML模板,我不知道我做错了什么 以下是我的主要收藏: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
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}}
{{/每个}}
它现在起作用了!:-) 重要的是,视图中的渲染方法是什么样子的?