好的,所以我找到了答案。
而不是從我自己的回調加載視圖,我現在從常規的ajax回調加載視圖。
在我的頁面上,我創建了視圖對象,並將配置添加到Drupal.settings。
$view = views_get_view('taxonomy_term');
$view->set_display('page');
$view->set_use_ajax(TRUE);
$view->set_arguments(array($tid));
$settings = array(
'views' => array(
'ajax_path' => url('views/ajax'),
'ajaxViews' => array(
array(
'view_name' => $view->name,
'view_display_id' => $view->current_display,
'view_args' => check_plain(implode('/', $view->args)),
'view_path' => check_plain($_GET['q']),
'view_base_path' => $view->get_path(),
'view_dom_id' => 1,
'pager_element' => $view->pager['element'],
),
),
),
);
drupal_add_js($settings, 'setting');
views_add_js('ajax_view');
然後我加載我的js,它將當前過濾器從location.hash添加到設置中。最後,加載視圖。
var data = {};
// Add view settings to the data.
for (var key in Drupal.settings.views.ajaxViews[0]) {
data[key] = Drupal.settings.views.ajaxViews[0][key];
}
// Get the params from the hash.
if (location.hash) {
var q = decodeURIComponent(location.hash.substr(1));
var o = {'f':function(v){return unescape(v).replace(/\+/g,' ');}};
$.each(q.match(/^\??(.*)$/)[1].split('&'), function(i,p) {
p = p.split('=');
p[1] = o.f(p[1]);
data[p[0]] = data[p[0]]?((data[p[0]] instanceof Array)?(data[p[0]].push(p[1]),data[p[0]]):[data[p[0]],p[1]]):p[1];
});
}
$.ajax({
url: Drupal.settings.views.ajax_path,
type: 'GET',
data: data,
success: function(response) {
var viewDiv = '.view-dom-id-' + data.view_dom_id;
$('#content > div.limiter').html(response.display);
// Call all callbacks.
if (response.__callbacks) {
$.each(response.__callbacks, function(i, callback) {
eval(callback)(viewDiv, response);
});
}
},
error: function(xhr) {
$('#content > div.limiter').html('<p id="artist-load-error">Error text.</p>');
$('#block-request-0').hide();
},
dataType: 'json'
});
這種方式,通過正常流動的觀點負載,一切按預期工作=)
真棒有這個這麼少的信息在網絡上(沒有驚喜那裏Drupal的)謝謝 – 2012-06-22 14:14:39