2010-07-28 27 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

相关问题