EditorGrid面板+按钮 - 重新加载数据问题

时间:2011-04-19 04:54:24

标签: ruby-on-rails extjs

我正在使用Rails在ExtJs中开发一个应用程序,其中有一个选项卡面板。主选项卡包含左侧的按钮列表。单击每个按钮将打开一个新选项卡,并将呈现网格或表单。当我从表单添加新记录时,它会立即显示在网格上,但如果我关闭选项卡面板并再次单击该按钮,则不会显示网格。

如何再次将数据与数据一起加载?

P.S:当我手动刷新浏览器时,它会再次显示!!

提前致谢!!

MyCode:

//** MyUnit.js in Units controller**//

MyUnit = Ext.extend(MyUnitUi, {
         initComponent: function() {
        MyUnit.superclass.initComponent.call(this);

             //Insert records...

                var sbtn=Ext.getCmp('btnSave');

                sbtn.on('click',function(){
                var grid = Ext.getCmp('maingrid');
                var unitname =  Ext.getCmp('unitname').getValue();
                var description =  Ext.getCmp('description').getValue();

                var frm=Ext.getCmp('myform');

                Ext.Ajax.request({
                url: '/units',
                method: 'POST',

                params: {'data[unitname]':unitname,'data[description]':description}

        });
                var grid=Ext.getCmp('maingrid');
                grid.store.reload();
                grid.show();
                frm.hide();
             });

});

//** MyViewport.js in Test1 Controller **//

    var unit_bt =Ext.getCmp('btnUnit');
       unit_bt.on('click', function(){
       var unit_el =Ext.getCmp('tabcon');
       var tab = unit_el.getItem('tab_unit');
       if(tab)
       {
           tab.show();
       }else{
            unit_el.add({
                title    : 'Unit of Measurement',
                html     : 'I am new unit',
                activeTab: 0,
                closable : true ,
                id: 'tab_unit',
                autoLoad:{url:'/units',scripts:true}
                //store.load({params:{start:0, limit:25}})

            }).show();
            }
       });

//** Units/index.html **//
<!DOCTYPE html>

<!-- Auto Generated with Ext Designer -->
<!-- Modifications to this file will be overwritten. -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>unit.xds</title>
    <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-3.3.1/resources/css/ext-all.css"/>
    <script type="text/javascript" src="http://extjs.cachefly.net/ext-3.3.1/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="http://extjs.cachefly.net/ext-3.3.1/ext-all-debug.js"></script>
    <script type="text/javascript" src="MyUnit.ui.js"></script>
    <script type="text/javascript" src="MyUnit.js"></script>
    <script type="text/javascript" src="MyUnitStore.js"></script>
    <script type="text/javascript" src="xds_index.js"></script>
</head>
<body></body>
</html>

1 个答案:

答案 0 :(得分:0)

@All:谢谢你的努力。好吧,我的朋友找到了解决方案

只需再次在units.js中添加以下代码行即可解决问题:

var grid=Ext.getCmp('maingrid');
grid.store.reload();