2010-07-28 29 views
3

如何在Ajax調用完成後重新加載自定義JavaScript文件?如何在Drupal進行Ajax調用後重新加載自定義JavaScript文件?

在我的情況下,我有一個自定義JavaScript文件來操縱視圖數據和 過濾器。它在第一次加載頁面時完美運行。

但是,一旦用戶設置了過濾器並點擊應用,即在Ajax調用之後,JavaScript似乎停止工作。它在那裏,但沒有註冊任何事件。

我閱讀了Drupal.org上的一些文章,但那並沒有給我一個可靠的解決方案。

注 - 它不是一個模塊.js文件,而是一個自定義獨立.js文件在主題文件夾下。

回答

1

的問題可能是 - 「我怎麼能火與更新上dupal回調參數的js函數」

這是我做過什麼:

我的形式是這樣的:

$form['letterdrop_id'] = array(      
    '#type' => 'select',        
    '#title' => 'Letterdrops',       
    '#options' => $letterdrops,      
    '#prefix' => '<div id="replace_div_ld">',   
    '#suffix' => '</div>',        
    '#ajax' => array(         
     'callback' => 'agc_ems_form_map_change',   
    ),            
    );             

與此回調函數:

function agc_ems_form_map_change($form, &$fstate) {    
    return array(             
    '#type' => 'ajax',           
    '#commands' => array(
     // this command is to reload a form element           
     ajax_command_replace("#agc_map", render($form['map'])),  
     // this command does the business and calls my custom function, 
     // with a parameter object supplied 
     array('command' => 'afterAjaxCallbackExample',    
      'selectedValue' => 'i am not a fish',     
    )                
));                
}                 

這是我的js函數

(function($, Drupal) {              
    // put function into drupal commands: 
    Drupal.ajax.prototype.commands.afterAjaxCallbackExample = 
    function(ajax, response, status) { 
    // response object as passed in our Ajax callback   
    // do what you want in here 
    alert(response.selectedValue);           
    };                   
}(jQuery, Drupal));  

100%的功勞jaypan

相關問題