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);
}