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 に答える