3

The Ratchet single-page application framework uses push.js to load new pages into view. For example:

<a href="link.html">link<a>

This will use push to replace everything in the .content div with the .content of link.html. It will also update .bar-title and .bar-tab if you have them on both pages.

I would like to use the same mechanism with a Javascript function call. Before I start patching Ratchet, is there an elegant way to do that?

Thanks!

4

3 回答 3

1

user2078515 的回答对我不起作用。options没有正确定义并且以这种方式定义函数不会将其置于全局范围内。PUSH 无论如何都在全局范围内,所以你可以这样做:

PUSH({
  url: 'file:///android_asset/www/userlist.html'
});

由于某种原因我无法transition上班,但这可能是一个单独的问题...

于 2014-09-09T14:03:01.640 回答
1

我一直在研究这个,发现 PUSH 只能使用完整的文件路径。因此,我创建了这个函数,可以这样调用:pushRedirectTo('my_page.html').

    function pushRedirectTo(path){
        var new_path = window.location.href.split('/');
        new_path.pop();
        path.replace('/', '');
        new_path.push(path);
        new_path = new_path.join('/');
        //alert('p: ' + new_path);
        PUSH({url: new_path, transition: 'fade'});
    }

感谢#mr-Chimp 的回答,帮助我解决了完整的路径问题。

于 2015-09-03T10:49:01.310 回答
0

它并不优雅,但您可以创建一个公开推送功能的全局函数。打开 ratchet.js 并添加

myGlobalPushFunction = function(){  PUSH(options)  }

在第 276 行附近(在 PUSH 函数上方)。然后像这样调用它:

myGlobalPushFunction({ url: "index2.html",  transition: "fade" })
于 2013-11-11T12:41:30.913 回答