backbone route demo

主要是两个用法,一个*获取路径。一个:获取参数。
问题:
API中的例子是
"folder/:name-:mode": "openFolder"
不知道是对应哪种path。

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<script src="lib/jquery-1.7.2.min.js" type="text/javascript"></script>
		<script src="lib/underscore-min.js" type="text/javascript"></script>
		<script src="lib/backbone-min.js" type="text/javascript"></script>
	</head>
	<body>
		<a href="#actions">test actions</a>
		 <a href="#posts/120">Post 120</a>
		<a href="#download/user/images/hey.gif">download gif</a>  
		<a href="#help/1">page</a> 
		<a href="#folder/david/group">folder</a> 
	</body>
	
	<script>
		(function ($){
			var AppRoute = Backbone.Router.extend({
				routes:{
					"posts/:id":"getPost",//传递参数 :表示将#符号后面的字符串当成参数
					"help/:page":         "help",
					 "download/*path":     "download",  //对应的链接为<a href="#download/user/images/hey.gif">download gif</a>  
    				"folder/:name/:mode": "openFolder",
    				"*actions":"defaultRoute", //对应的链接为#actions
				},
				defaultRoute:function(actions){
					console.log("defult");
					alert(actions);
				},
				help:function(page){
					alert(page);
				},
				openFolder:function(route,action){
					console.log("folder");
					alert(route + "_" + action);
				},
				getPost:function(id){
					alert(id);
				},
				download:function(path){
					 alert(path); // download/user/images/hey.gif   
				},
			});
			var route = new AppRoute;
			Backbone.history.start();
		})(jQuery);
	</script>
</html>

你可能感兴趣的:(backbone)