0
我有兩個不同的視圖,需要在節點頁面上進行切換。我不能將這兩個視圖放在一起,所以我創建了一個基本上將我創建的表單的值並將它們作爲參數發送到視圖並顯示視圖的表單。我正在嘗試使用這個Ajax。它工作正常,但問題是我第二次運行它不刷新或更新該視圖的表單。Drupal Ajax表單Ajax表單來拉兩個不同的視圖
function photoflight_albums() {
photoflight_gallery_themes();
$output = render(drupal_get_form('photoflight_gallery_form'));
$output .= "<div id='gallery-ajax-wrapper'>";
$output .= views_embed_view('gallery', 'default');
$output .= "</div>";
return $output;
}
//Grabs the node titles
function photoflight_gallery_themes(){
$type = "photo_theme";
$theme_list = array();
$nodes = node_load_multiple(array(), array('type' => $type));
foreach($nodes as $themes){
$theme_list[$themes->title] = $themes->title;
}
return $theme_list;
}
//Form calls back to the function above to the gallery-ajax-wrapper div output above
function photoflight_gallery_form($form, &$form_state){
$form = array();
$form['themes'] = array(
'#type' => 'select',
'#options' => array(photoflight_gallery_themes()),
'#ajax' => array(
'callback' => 'photoflight_simplest_callback',
'wrapper' => 'gallery-ajax-wrapper',
),
);
//debug($form);
return $form;
}
//Ajax callback
function photoflight_simplest_callback($form, $form_state) {
$view = views_get_view('gallery');
$args = array('title' => $form_state['values']['themes']);
$view->set_exposed_input($args);
$output = $view->preview('default', $args);
return array("#markup" => $output);
}