director.js

作者:王然 kxxoling@gmail.com

简介

director 提供前端和后端的 路由解决方案,可以用于控制前端路由以及页面代码的显示与否。

使用很简单:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Director Example</title>
  6. <div id="results"></div>
  7. <script src="http://www.javascriptoo.com/application/html/js/flatiron/director/director.min.js"></script>
  8. <script>
  9. var r = document.getElementById('results');
  10. var data = {
  11. people: [
  12. { 'firstName': 'Clark', 'lastName': 'Kent' },
  13. { 'firstName': 'Bruce', 'lastName': 'Wayne' },
  14. { 'firstName': 'Peter', 'lastName': 'Parker' }
  15. ]
  16. }
  17. var viewPerson = function(personId) { r.innerHTML = data.people[personId].firstName + ' ' + data.people[personId].lastName; };
  18. var routes = {'/person/view/:bookId': viewPerson};
  19. var router = Router(routes);
  20. router.init();
  21. </script>
  22. </head>
  23. <body>
  24. <ul>
  25. <li><a href="#/person/view/0">Clark</a></li>
  26. <li><a href="#/person/view/1">Bruce</a></li>
  27. <li><a href="#/person/view/2">Peter</a></li>
  28. </ul>
  29. </body>
  30. </html>

效果预览: GitHub Pages