无法使用Backbone.js访问模板视图中的li标签

时间:2015-11-04 17:35:44

标签: javascript jquery backbone.js

我创建了一个主视图和子视图但是,似乎我无法访问我附加了我的子视图的ul标签(主视图)中的我的li标签(子视图)。任何指向我正确方向的建议都会很棒!谢谢!

浏览

// View for all people
CardAppInitilazer.cardApp.Views.Peoples = Backbone.View.extend({

    el: 'ul.card-grid',
    peopleCollection:function() {
        var people = new CardAppInitilazer.cardApp.Collections.People;
        var getPeople = people.fetch();

        return getPeople;
    },
    render: function() {
        var _self = this;


        _self.peopleCollection().then(function(person) {
            // console.log(person);

            _.each(person, function(model) {
                // console.log(model);

                var peopleView = new peopleInstance({model:model});
                console.log(peopleView);

                _self.$el.append(peopleView.render().el);
            }.bind(this));

        }, function( model, response ) {
            console.log(response + ' could not load model ' + model);
        });

        return this;
    },
    initialize:function() {
        this.render();
    }
});


//View for people
CardAppInitilazer.cardApp.Views.People = Backbone.View.extend({

  tagName: 'li',

  className:'card-list',

  template: _.template($('#peopleTemplate').html()),

  render: function() {
    this.$el.html(this.template(this.model));

    return this;
  }

});

var peoplesView = new CardAppInitilazer.cardApp.Views.Peoples;
var peopleInstance = CardAppInitilazer.cardApp.Views.People;

模板

<ul class="card-grid"></ul>
            <script id="peopleTemplate" type="text/template">
                <a href="#" data-largesrc="<%= image %>" data-title="<%= image %>" data-description="<%= description %>" class="card-content">
                    <h2><%= title %></h2>
                    <img src="<%= image %>" alt="<%= title %>"> 
                </a>
            </script>

0 个答案:

没有答案