【问题标题】:How to implement jqGrid with Marionette?如何用 Marionette 实现 jqGrid?
【发布时间】:2013-06-24 15:05:39
【问题描述】:

我正在尝试在我的 Marionette 应用程序中渲染 jqGrid,一切正常,直到我找不到渲染寻呼机的方法。 我正在使用包含模板的 Handlebars,这是代码:

hb template:
    <script id='llantas_grid_tmpl' type='text/x-handlebars-template'>
        <table id='llantas_catalog_list'></table>
        <div id="llantas_catalog_pager">pager</div>
    </script>


layout...


    ui: {
            table: '#llantas_catalog_list',
            pager: '#llantas_catalog_pager'
        },

    onRender: function(){
            var table           = this.ui.table,
                pager           = this.ui.pager;          

            table

                .jqGrid({
                    url: '/llantas',
                    datatype: "json",
                    colNames:['Id','Orden De Compra', 'Marca', 'Medida', 'Modelo'],
                    colModel:[
                        {name:'id',index:'id', width:55},
                        {name:'ordencompra',index:'ordencompra', width:90},
                        {name:'marca',index:'marca', width:90},
                        {name:'medida',index:'medida', width:90},
                        {name:'modelo',index:'modelo', width:90}
                    ],
                    rowNum:10,
                    rowList:[10,20,30],
                    pager: '#llantas_catalog_pager',
                    width:1060,
                    height:375,
                    sortname: 'id',
                    viewrecords: true,
                    sortorder: "desc",
                    caption:"<h3>Catalogo llantas<h3>"
                });

            table
                .jqGrid('navGrid','#llantas_catalog_pager',{edit:false,add:false,del:false});    

        }

有没有办法将寻呼机占位符设置为 jqGrid 对象? 像这样:

table
.jqGrid('navGrid',pager,{edit:false,add:false,del:false});    

编辑:请仅在您了解 BACKBONE Marionette 和 JQGRID 的情况下回答。

【问题讨论】:

  • pager的值是多少?
  • 这是一个来自模板的 jQuery 对象。

标签: backbone.js jqgrid marionette


【解决方案1】:

一句话,没有。

jqGrid does a check 确保它是一个字符串,

if(!$t.grid || typeof elem !== 'string') {return;}

您需要修改 jqGrid 源代码。

【讨论】:

【解决方案2】:

我找到了让它工作的方法:

一旦子视图(我试图用 jqGrid 渲染的那个)被渲染并显示在主视图的区域中,我只需搜索模板表选择器并在 jqGrid 分页器选项中传递分页器 ID。

主布局...

onRender: function(){

        // llantasGridView is the view holding only the template without the jqGrid (I erased everything)    
        var llantasGridView = new LlantasGrid.View();

        // table_container is the region that will hold the llantasGridView template
        this.table_container.show( llantasGridView );

        // once is rendered I search for the table
        var table = llantasGridView.$el.find('#llantas_catalog_list');

        // here I pass the jqGrid 
        table
            .jqGrid({
                url: G.API + '/llantas',
                datatype: "json",
                colNames:['Id','PO'...

                pager: '#llantas_catalog_pager', // pager for grid is now being displayed
...

【讨论】:

  • 渲染 jqgrid 时是在 Itemview 还是 collection view 中渲染,我想这两种都不合适,我应该使用扩展常规 Backbone 视图的视图吗?
猜你喜欢
  • 2013-12-17
  • 2016-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-23
  • 2012-05-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多