Backbone上的Fuelux数据网格js NAN错误,没有数据

时间:2013-05-14 16:18:37

标签: javascript backbone.js require fuelux

我正在使用Backbone,Require,Fuelux,Bootstrap作为我的单页Web应用程序,我正在尝试使用Fuel UX datagrid来处理这个问题,我可以看到返回了正确的对象集,这很好但是数据没有在页数统计下使用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
    };
});

Array of objects returned

0 个答案:

没有答案