extJS 函数用不了,直接把函数写到里面就可以
代码如下:
 Ext.onReady(function() {            var cm = new Ext.grid.ColumnModel([
        { header: '编号', dataIndex: 'ProdID' },
        { header: '名称', dataIndex: 'Name' }
    ]);
            var ds = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({ url: 'getProduct.aspx', method: 'GET' }),
                reader: new Ext.data.JsonReader({
                    totalProperty: 'totalCount',
                    root: 'topics'
                }, [
            { name: 'ProdID' },
            { name: 'Name' }        ])
            });            var grid = new Ext.grid.GridPanel({
                el: 'grid',
                ds: ds,
                cm: cm,
                height: 500,
                bbar: new Ext.PagingToolbar({
                    pageSize: 10,
                    store: ds,
                    displayInfo: true,
                    displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
                    emptyMsg: "没有记录"
                }),
                tbar: [{ text: "delete", pressed: true, handler: doDel}]            });
            grid.render();
            ds.load({ params: { start: 0, limit: 10} });
            var doDel = function() {
                alert('d');
            }
        }); 
为什么doDel函数执行不了呢?

解决方案 »

  1.   

    我想应该是作用域的问题,根据我的经验这在于是不是new出来的(里面就是作用域),函数应该作为你创建的对象的一个属性,如果不在里面定义的话那就是一个新的对象了,不好意思我也说不太清楚,毕竟道行还不深呵呵,有机会多交流下吧.
      

  2.   

    我在网上找了很多例子,差不多都是这样,不知为什么就是不行
    EXTJS我也是刚刚接触,有机会多多交流下
      

  3.   

    把那个函数写到grid组件上面就行啦, 哎
    为什么呢?
      

  4.   

    应该有两个办法
    1.
    var doDel = function() {
      alert('d');
      }
    放到grid定义的前面去2.
    位置不变
    var doDel = function() {
      alert('d');
      }
    不要使用单例模式,改成类型
    function doDel {
      alert('d');
      }