0

我正在为我的单页 Web 应用程序使用 Backbone、Require、Fuelux、Bootstrap,我正在尝试让 Fuel UX 数据网格与它一起工作,我可以看到返回了正确的对象集,这很好,但数据没有得到插入到表中,NaN 在页数下,表中的所有其他字段为空。

唯一正确返回的是返回的对象数量。这怎么可能?

define([
    'jquery',
    'underscore',
    'Backbone',
    'fuelux',
    'sampleData',
    'datasource',
    'bootstrap',
    'qunit',
    'bootstrapDatepicker'
], function($, _, Backbone, fuelux, sampleData, datasource, Bootstrap, Qunit, Datepicker){

    var initialize = function(){

        var ReportModel = Backbone.Model.extend({
            urlRoot: '/CareersAndJobs/cnj_report',
            initialize: function(){
                // console.log('test');
            }/*,
            defaults: function(){
                return {
                    fromDate: new Date(),
                    toDate: '',
                    limit: 10
                }
            }*/
        });

        var ReportCollection = Backbone.Collection.extend({
            url: '/CareersAndJobs/cnj_report',
            model: ReportModel
        });

        var ReportData = new ReportModel(sampleData.geonames);


        var ReportRouter = Backbone.Router.extend({
            initialize: function(){
                Backbone.history.start();
            },

            routes: {
                '' : 'main'
            },

            'main': function(){
                // console.log('main test');
                $ = jQuery;
                $('#fromDate').datepicker().on('changeDate', function(e){
                    $('#toDate').datepicker('setStartDate', new Date(e.date.valueOf()));
                });
                $('#toDate').datepicker().on('changeDate', function(e){
                    $('#fromDate').datepicker('setEndDate', new Date(e.date.valueOf()));
                });
                sidebarwidth = $(".sidebar-width").css('width');
                bodypaddingtop = $(".navbar-fixed-top").css('height');
                sidebarheight = $("body").css('height');
                $('.sidebar-nav-fixed').css('width', sidebarwidth);
                $('.sidebar-nav-fixed').css('height', sidebarheight);
                $('body').css('paddingTop', bodypaddingtop)
                contentmargin = parseInt(sidebarwidth)
                $('.span-fixed-sidebar').css('marginLeft', contentmargin);
                $('.span-fixed-sidebar').css('paddingLeft', 60);
            }
        });



        Collection = new ReportCollection(ReportData);




        var ReportView = Backbone.View.extend({
            el: $('#container'),
            initialize: function(){
                Collection.fetch();
                _.bindAll(this, 'render', 'submit_form');
                this.render();
            },
            events: {
                "click #submit": "submit_form"
            },
            render: function(){



                // INITIALIZING THE DATAGRID
                var dataSources = new datasource({
                    columns: [
                        {
                            property: 'toponymName',
                            label: 'Name',
                            sortable: true
                        },
                        {
                            property: 'countrycode',
                            label: 'Country',
                            sortable: true
                        },
                        {
                            property: 'population',
                            label: 'Population',
                            sortable: true
                        },
                        {
                            property: 'fcodeName',
                            label: 'Type',
                            sortable: true
                        }
                    ],
                    data: ReportData.toJSON(),
                    delay: 250
                });
                console.log(ReportData.toJSON());

                $('#DataGrid').datagrid({
                    dataSource: dataSources,
                    stretchHeight: true
                });

                return this;
            },
            submit_form: function(){

                data = Collection.fetch();
                console.log(data);
            }
        });

        var ReportView = new ReportView;

        ReportRouter = new ReportRouter();

        ReportRouter.on('router:main', function(){
            console.log('router test');
            ReportView.render();
        });
    };

    return {
        initialize: initialize
    };
});

返回的对象数组

4

0 回答 0