2011-01-05 53 views
0

我正在考慮將當前的應用程序移植到使用JavascriptMVC + RESTful Web服務。但是,我不確定是否可以使用JavascriptMVC創建可收藏的URL。JavascriptMVC是否支持可加入書籤的URL?

例如:web應用程序是一個應用程序託管的課程,並有像

/場/ RDBMS /講座網址/ 1

是否有可能創造這樣的URL與JavascriptMVC?

回答

2

你可以考慮使用jQuery.address(http://www.asual.com/jquery/address/)來管理你的URL。

jQuery.address允許您設置可抓取的URL,例如「http://example.com/#!/user/5」並偵聽地址更改並採取相應措施。

在我自己的代碼中,我從盜取配置文件中設置了一個基於地址的路由器,如下所示。

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

您可以通過

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

或者從JS土地通過

$.address.value('/user/10/profile');