精品学习网->精美文摘

上一篇    全部文章


    BackboneJS  Backbone.history.start()方法
  
    它跟踪历史相匹配的合适的路由,触发回调来处理事件并启用在应用程序中的路由。

    开始
    这是可被用于操纵BackboneJS-历史的唯一方法。它开始监听路由和管理历史可标记的URL。

    语法
    Backbone.history.start(options)

    参数:
    options: 这些选项包括历史使用的参数,如pushState和hashChange。

    示例

  
  
   History  Example
   
   
   
  
    
    //'Router'  is  a  name  of  the  router  class
    var  Router  =  Backbone.Router.extend({

    //The  'routes'  maps  URLs  with  parameters  to  functions  on  your  router
    routes:  {
        "myroute1"  :  "myFunc1",
       "myroute2"  :  "myFunc2"
       "myroute3"  :  "myFunc3"
    },

    //'The  function  'myFunc'  defines  the  links  for  the  route  on  the  browser
    myFunc1:  function  (a)  {
      document.write("You  click  Route1!");
    },

    myFunc2:  function  (a)  {
      document.write("You  click  Route2!");
    },

    myFunc3:  function  (a)  {
      document.write("You  click  Route3!");
    }
   });

    //'router'  is  an  instance  of  the  Router
    var  router  =  new  Router();

    //Start  listening  to  the  routes  and  manages  the  history  for  bookmarkable  URL's
    Backbone.history.start();
  
  
    
  MyRoute1  

  MyRoute2  

  MyRoute3  

  
  


    输出结果

  MyRoute1
  MyRoute2
  MyRoute3

  点击MyRoute1,显示:You  click  Route1!
  点击MyRoute2,显示:You  click  Route1!
  点击MyRoute3,显示:You  click  Route1!
    
FALSE

     返回顶部
Backbone.history.start()方法