0

我从 Backbone 和 Laravel 开始,我有几个问题,因为我在西班牙语中找不到任何东西(也许我不知道如何搜索,因此更容易问)。

这是我的模型:

window.mMateria = Backbone.Model.extend({
    defaults: {
        nombremateria: ""
    },
});

window.cMaterias = Backbone.Collection.extend({
    url: "materias",
    model: mMateria,
    initialize: function() {
        this.fetch();
    }
});

以下是我的看法:

window.vMaterias = Backbone.View.extend({
    tagName: 'ul',
    model: cMaterias,
    className:'list-materias',

    initialize: function () {
        _.bindAll(this, "render");
    },
    render: function(){
        $(this.el).append("Renderizando!"); //It appears
        _.each(this.model.models, function (aMater) {
            console.log(aMater); //HERE IT DOESN'T ENTER, doesn't show anything
            $(this.el).append(new vMateria({model:aMater}).render().el);
        }, this);
        return this;
    },
    el: $(".container-fluid")
});

window.vMateria = Backbone.View.extend({
    initialize:function () {
        _.bindAll(this, "render");
        this.model.bind("change", this.render(), this);
    },
    render: function() {
        this.$el.html(this.template(this.model.toJSON()));
        return this;
    }, 
    className: "item-materia",
    el: $(".container-fluid"),

    template: _.template($('#pl_materia').val()),
});

然后初始化:

    cmaterias = new cMaterias(); 
    console.log(cmaterias); //it returns 41 signatures
    vmaterias = new vMaterias({model: cmaterias});
    console.log(vmaterias); //Shows child {cid: "view1", model: child, ... 
    vmaterias.render().el;

请帮助我并原谅我的英语,我不知道 Laravel return Response::eloquent(Materia::all());是否是问题所在。尽可能具体。迪奥斯洛斯本迪加。

4

1 回答 1

0

试试这些改变。

window.vMaterias = Backbone.View.extend({
    tagName: 'ul',
    className:'list-materias',
    render: function(){
        this.$el.empty();
        this.$el.append("Renderizando!"); //It appears
        this.collection.each(function (aMater) {
            console.log(aMater); //HERE IT DOESN'T ENTER, doesn't show anything
            this.$el.append(new vMateria({model:aMater}).render().el);
        }, this);
        return this;
    },
    el: $(".container-fluid")
});

cmaterias = new cMaterias(); 
console.log(cmaterias); //it returns 41 signatures
vmaterias = new vMaterias({collection: cmaterias});
于 2013-03-13T00:22:54.740 回答