我正在使用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;
}
首先是這個「好辦法」要做到這一點,因爲我那種失去信心:) 第二個問題,如何顯示在頁面加載的數據,現在分辯需要改變一個複選框看到一些信息。
感謝和遺憾的簡短描述:)