English 中文(简体)
Does JavascriptMVC support bookmarkable URLs?
原标题:

I am thinking of porting my current application to use JavascriptMVC + RESTfull web services. However, I am not sure if I can create bookmarkable URLs with JavascriptMVC.

For example: the webapp is an app to host courses, and will have URLs like

/courses/RDBMS/lecture/1

Is it possible to create such URLs with JavascriptMVC?

最佳回答

You could consider using jQuery.address ( http://www.asual.com/jquery/address/ ) in order to manage your URLs.

jQuery.address allows you to set crawlable URLs such as "http://example.com/#!/user/5" and listen for address changes and act accordingly.

In my own code, I set up an address based router from within the steal configuration file as follows.

steal.plugins(
           jquery/controller ,
           jquery/controller/subscribe ,
           jquery/view/ejs ,
           jquery/controller/view ,
           jquery/model ,
           jquery/dom/fixture ,
           jquery/dom/form_params ,
           steal/less )                   
    .css( css/vendor/reset-fonts-grids )
    .resources( vendor/jquery.address-1.3.1.min.js )
    .models( user )
    .controllers( user )
    .views()
    .then(function() {
        steal.less( css/style );

        // Set up a router
        $.address.baseURL( /basePath );

        // $.address.crawlable(true);
        $.address.change(function(event) {
            var path = event.path;
            switch(true) {
            // Matches http://example.com/#!/ or http://example.com/
            case /^/$/.test(path):
                $( #page ).empty();
                break;
            // Matches http://example.com/#!/user/42/profile
            case /^/user/[0-9]+/profile/.test(path):
                var userId = path.split("/")[2];
                // Instantiate and load a controller
                new User.Controllers.User($( body ),userId);
                break;
            case /^/search/.test(path):
                $.log( search );
                break;
            default:
                $.log(event.path);
            }
        });
    });

You can then call a new page from HTML-land via

<a href="/" onclick="$.address.value( / ); return false;">root url</a>

Or from JS land via

$.address.value( /user/10/profile );
问题回答

You can use JavascriptMVC Router, it s the same as jQuery.address but is integrated with JavascriptMVC: http://javascriptmvc.com/docs.html#!jQuery.route





相关问题
Using Backbone.js offline

I m evaluating Backbone.js for keeping data and UI synchronized in my web app. However, much of Backbone s value seems to lie in its use of RESTful interfaces. Though I may add server-side backup in ...

Server-side vs. Client-side (AJAX) Loading

I was wondering what is considered best practice. Let s say I have a dropdown select widget. Should it be preloaded with content when the page is served up from the server or once it is loaded, should ...

integrate yui with javascriptmvc

How to integrate yui with javascriptmvc? I want to use yui3.Tabview in my application based on javascriptMVC.

Does JavascriptMVC support bookmarkable URLs?

I am thinking of porting my current application to use JavascriptMVC + RESTfull web services. However, I am not sure if I can create bookmarkable URLs with JavascriptMVC. For example: the webapp is ...

Using Selenium-IDE with a rich Javascript application?

Problem At my workplace, we re trying to find the best way to create automated-tests for an almost wholly javascript-driven intranet application. Right now we re stuck trying to find a good tradeoff ...

荣誉勋章或书籍

我已经熟悉了javascript,但正在寻找一个全面的辅导或书,从最基本的内容来看,教我如何建立与乳房设计模式的接口。

Just In General: JS Only Vs Page-Based Web Apps

When a developing a web app, versus a web site, what reasons are there to use multiple HTML pages, rather than using one html page and doing everything through Javascript? I would expect that it ...

sproutcore vs javascriptMVC for web app development

I want to use a javascript framework with MVC for a complex web application (which will be one of a set of related apps and pages) for an intranet in a digital archives. I have been looking at ...

热门标签