2012-01-07 89 views
1

我有一個簡單的網格置於這樣的列是一個「下載」鏈接之一:ExtJS的domquery問題

{ 
    header: 'Config files', 
    width: 130, 
    sortable: false, 
    fixed: true, 
    renderer: function() { 
     return '<a href="javascript:void(0);" class="downloadCfg">Download</a>'; 
    } 
} 

這是在視圖中。現在移動到控制器我放在聽者對電網趕只要點擊這個鏈接:

init : function() { 
    this.control({ 
     'accountFiles a[class=downloadCfg]': { 
      click: function() { 
       alert('test'); 
      } 
     } 
    }); 
} 

非常基本的,但它不工作。是否因爲鏈接是通過網格的「渲染器」功能創建的?有任何想法嗎?

回答

1

@Romeo

這是你如何抓住下載鏈接是否被點擊與否:

'accountFiles': { 
      itemclick: function(thisView, record, item, index, e, eOpts) { 
       var t = e.getTarget('.downloadCfg'); 

       if (!Ext.isEmpty(t)) 
        alert('Download clicked!!'); 
       else 
        alert('Other item clicked!!'); 
      } 
     } 

一旦你已經確定了下載鏈接被點擊,你有一個包含完整記錄記錄代表該行。

0
accountFiles a[class=downloadCfg] 

將選擇的accountFiles標籤,它有一個標籤的所有後代。並按類屬性過濾它們。

在我看來,您已將它與ComponentQuery語法混淆在一起,您可以通過組件ID而不是通過標記來選擇它。

+0

不,它不會混淆。我想在點擊「downloadCfg」類的鏈接時抓取動作。該鏈接呈現在每行的網格中。 – 2012-01-07 09:04:19

1

我不知道如何解決這個問題,但我知道另一種解決方案。

在GridPanel中創建方法:

doDownload: function(recordId) { 
    var record = this.getStore().data.get(recordId); 
    // do something 
} 

然後創建改變渲染器:

renderer: function(value, meta, record, rowIndex, colIndex, store) { 
    return '<a href="#" onclick="Ext.getCmp(Ext.get(this).parent(\'.x-grid\').id).doDownload(\'' + store.data.getKey(record) + '\')">Download</a>'; 
} 

行動onclick處理程序嘗試使用DOM類找到網格。