我正在使用drupal 7模块,我希望使用ajax过滤器在页面上打印信息(MENU_LOCAL_TASK节点/%node/something)。 我创建了一个表单并添加了2个复选框,其中1个默认其他不是。我想根据所选的复选框向用户显示信息。 1在表格行1上显示,2在表格2上显示。如果其中一部分关闭,则表格行关闭。我有没有提到,我想解决它没有提交和重新加载,只有ajax。 我添加到两个'复选框'以下'ajax' => array('callback' => 'my_module_callback')
。这是其余的代码,简单。drupal ajax表单更改
function my_module_callback($form, $form_state) {
$data = array();
$nid = 1;
if ($form_state['values']['checkbox1']) {
$data += load_data($nid, "checkbox1");
}
if ($form_state['values']['checkbox1']) {
$data += load_data($nid, "checkbox2");
}
$commands[] = ajax_command_html("#here", my_module_table($data));
return array('#type' => 'ajax', '#commands' => $commands);
}
function my_module_table($data){
//do some stuff with the data in a foreach
return theme("my_module_fancy_table",array("data" => $data));
}
function theme_my_module_fancy_table($data){ //registered with my_module_theme()
// putting html into $output in a foreach
return $output;
}
function my_module_page_callback_from_menu_function($nid){
$output = drupal_render(drupal_get_form('my_module_custom_ajax_form'));
$output .= "adding other stuffs including div#here";
return $output;
}
首先是这个“好办法”要做到这一点,因为我那种失去信心:) 第二个问题,如何显示在页面加载的数据,现在分辩需要改变一个复选框看到一些信息。
感谢和遗憾的简短描述:)