0

在单个 html 内的页面之间导航的推荐方法是什么。例如,列表页面 (#listId) 内容和详细信息页面 (#detailsId) 内容都有占位符。我们应该使用 jquery 显示/隐藏到 #listId 还是 #detailsId 与 canjs 路由机制?

canjs 是否支持类似的方法http://api.jquerymobile.com/jQuery.mobile.changePage/

4

1 回答 1

0

It will be better if you use the canjs routing, in that way users can copy the link for that page and it will show the correct content when shared. So you could have a control that looks something like:

APP.MainControl = can.Control({
    init: function (ele, options) {
        var view = can.view('t-main', {});
        ele.append(view);
        can.route.ready();
    },

    'list route': 'showList',

    'details route': 'showDetails',

    showList: function (data) {
        // You can load a can view here, 
        // a can controller or just use jquery to show the element
    },

    showDetails: function (data) {
        // ...
    },

});

Alternatively, you can have a can component on the page that binds to can.route, but I don't have an example for that.

于 2014-06-12T06:43:29.790 回答