2015-02-04 3 views
0
var MyView = Backbone.View.extend({ 
       template: $('#my-view-template').html(), 

       render: function (source) { 

        // compile the Underscore.js template 
        var compiledTemplate = _.template(this.template); 

        // render the template with the model data 
        var data = _.clone(this.model.attributes); 
        var html = compiledTemplate(data); 

        this.template.$(".aVideo") 
        this.$aVideo = this.$('#aVideo'); 
        this.$aVideo.attr("href", source);     
        this.$el.append(html);     
       } 
      }); 

    <script type="text/html" id="my-view-template"> 

     <div style="border:1px solid firebrick; padding:15px; color:firebrick"> 
       <a class="btn btn-link" id="aVideo" target="_blank" style="font-size:15px;">View Trailer</a> 
      </div> 
     </div> 

    </script> 

$.ajax({ 
      url: '/Movie/Movies', 
      dataType: "json", 
      type: "GET", 
      contentType: 'application/json; charset=utf-8', 
      success: function (data) { 
       for (var i = 0; i < data.length; i++) { 
        var movie1 = new Movie({ 
         "title": data[i].TITLE, 
         "description": data[i].DESCRIPTION, 
         "storyline": data[i].STORYLINE, 
         "rating": data[i].RATING, 
         "infobar": data[i].INFOBAR, 
         "director": data[i].DIRECTOR, 
         "stars": data[i].STARS 
        }); 

        var myView = new MyView({ 
         model: movie1 
        }); 

        myView.setElement("#content");      
        myView.render(data[i].VIDEO); 
       } 
      }, 
      error: function (xhr) { 
       alert('error'); 
      } 
     }); 

Каждое видео становится последним видео трейлером. Я не понимаю, почему я получаю последнее видео для каждого фильмаМагистральный шаблонный элемент, отображающий ошибки

ответ

-1

Я нашел альтернативный способ для своей проблемы. Спасибо!

<a class="btn btn-primary" id="aVideo" target="_blank" href="<%= video %>" style="font-size:15px;">View Trailer</a> 
+0

Просьба поделиться им! Сайт работает только хорошо, если люди разделяют как вопросы, так и ответы. –

Смежные вопросы