현재 백본을 학습 중이며 첫 번째 앱을 만들려고합니다. 학습 도구로서 사용자 ID별로 Vimeo 갤러리를 렌더링하려고합니다.백본/Vimeo API - 로깅을 표시하지만 렌더링하지 않습니다.
나는 모든 것을 정리하고 내보기가 올바르게 로깅되지만 페이지에 렌더링되지 않습니다. 나는 이것을 몇 시간 동안 풀려고 노력했지만, 내가 어디로 잘못 갔는지 확신하지 못한다. 어떤 통찰력이라도 대단히 감사하겠습니다. 내 접근 방식이 맞습니까?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Backbone App</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.1/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
</head>
<body>
<div id="video-container">
<script type="text/template" id="video_template">
<h1><%= video_title %></h1>
</script>
</div>
<script>
(function($){
var vimeoUser = 9836759;
var Video = Backbone.Model.extend({});
var VideoCollection = Backbone.Collection.extend({
model: Video
});
var VideoView = Backbone.View.extend({
tagName: 'li',
initialize: function(){
_.bindAll(this, 'render');
this.render();
},
render: function(){
var variables = {video_title: this.model.attributes.title};
var template = _.template($('#video_template').html(), variables);
// Logging element works
console.log(template);
// Rendering does not work
this.$el.html(template);
}
});
var GalleryView = Backbone.View.extend({
tagName: 'ul',
initialize: function(){
this.render();
},
render: function(){
this.collection.each(function(video){
var videoView = new VideoView({ model: video});
}, this);
}
});
// Create instance of VideoCollection
var VideoGallery = new VideoCollection;
$.ajax({
url: 'http://vimeo.com/api/v2/' + vimeoUser + '/videos.json',
dataType: 'jsonp',
success: function(response) {
// map api results to our collection
var videos = _.map(response, function(video) {
return {
title: video.title,
details: video.description,
thumbnail_large: video.thumbnail_large,
video: 'http://player.vimeo.com/video/' + video.id + '?api=1&player_id=vimeo-player&autoplay=1'
}
});
// add vimeo videos to collection
VideoGallery.add(videos);
var galleryView = new GalleryView({ el: $('#video-container'), collection: VideoGallery });
}
});
})(jQuery);
</script>
</body>
</html>
대단히 감사합니다. 위대한 작품이며 완벽한 의미를 갖습니다. – idealboy