0

バックグリッドのレンダリング中

<table class="backgrid"></table>

しかし他には何もありません。Backgrid:render() のブレークポイントに達していません。私はバックボーンの初心者なので、何が起こっているのか正確にはわかりませんが、 LayoutManager:render() が呼び出されます..バックグリッドに到達しないようです...表示したいデータがフェッチされていますそれらが正しい形式であるかのように見えます...しかし、Backbone コレクションにまとめられると、見分けるのが難しいことを認めなければなりません。デバッグ方法/Backgrid のレンダーが呼び出されない理由についてのポインタは、感謝して受け取りました。

以下のコード:

ListenView.js

define([
    'backbone',
        'underscore',
        'backgrid',
    'app/models/PersonModel',
    'app/collections/PersonCollection',
    'app/views/PersonListView',
    'hbs!app/templates/listen_template'
    ],
    function(
    Backbone,
        _,
        Backgrid,
        Person,
    PersonCollection,
    PersonListView,
    listenTemplate
    ) {

    App = window.App || {};
    var ListenView = Backbone.View.extend({
        template: listenTemplate,
        initialize: function(params) {
            //fetch the list of seen people
            this.model.attributes.seenPeople.fetch( {
                success: function(coll, resp) {
                    //console.log(coll);
                }
            });
        },
        afterRender: function() {
            //initialise person view
        console.log("creating Backgrid");
        this.seenPeopleView = new Backgrid.Grid({
                        columns: [{
                                name: "email",
                                label: "Email",
                                cell: "string"  
                        },{
                                name: "id",
                                label: "ID",
                                cell: "integer"  
                        }, {
                                name: "title",
                                label: "Title",
                                cell: "string" }
                        ],
                        collection: this.model.attributes.seenPeople
                    });
            this.seenPeopleView.render();
                $('#seen-people-list').append(this.seenPeopleView.el);
    }
4

2 に答える 2

0

ビュー (this.seenPeopleView) でバックグリッド インスタンスを作成する代わりに、インスタンスを次のように作成します。

var grid = new Backgrid.Grid({...<your columns and collection related code>..});

次に、グリッドをレンダリングし、ルートを HTML ドキュメントに次のようにアタッチします。

$('#seen-people-list').append(grid.render().el);

それがうまくいくことを願っています:)

于 2016-03-04T07:29:50.513 に答える
0

fetch からの成功メソッドでは、afterRender を呼び出す必要があります。

 var self=this;
 this.model.attributes.seenPeople.fetch( {
     success: function(coll, resp) {
                self.afterRender();
            }
 });
于 2016-03-01T20:59:09.707 に答える