• Ember.js demo5


    <!DOCTYPE html>
    <html>
    <head>
      <meta name="description" content="Ember: Routes, {{outlet}}, and {{#linkTo}}" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.js"></script>
    <script src="http://ember101.com/jsbin/ember.rc3.js"></script>
    <meta charset=utf-8 />
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
    <title>Episode 5</title>
    </head>
    <body>
      
      <script type="text/x-handlebars">
        <div class="container">
          <div class="row-fluid">
            <ul class="nav nav-list span3 well">
              {{#each model}}
              <li>{{#linkTo "user" this}}{{first}}{{/linkTo}}</li>
              {{/each}}
            </ul>
            <div class="span9 well">{{outlet}}</div>
          </div>
        </div>
      </script>
    
      <script type="text/x-handlebars" id="user">
        <h2>
          {{first}} {{last}}
          <img {{bindAttr src="avatar"}} class="pull-right" width=50 />
        </h2>
        <dl>
          <dt>First</dt>
          <dd>{{first}}</dd>
          <dt>Last</dt>
          <dd>{{last}}</dd>
        </dl>
        {{#linkTo "editUser" this class="btn btn-primary"}}Edit{{/linkTo}}
      </script>
    
      <script type="text/x-handlebars" id="editUser">
        <h2>Edit User</h2>
        <form class="form-inline" {{action save on="submit"}}>
          <label>
            First:
            {{input type="text" value=first}}      
          </label><br>
        
          <label>
            Last:
            {{input type="text" value=last}}        
          </label>
        
          <div class="controls">
            <button type="submit" class="btn btn-primary">Done</button>
          </div>
        </form>
      </script>
      
    </body>
    </html>
    body { margin-top: 30px }
    
    .active {
      color: red !important;
    }
    var App = Ember.Application.create();
    
    App.Router.map(function() {
      this.resource('user', {path: '/users/:user_id'});
      this.resource('editUser', {path: '/users/:user_id/edit'});
    });
    
    App.ApplicationRoute = Ember.Route.extend({
      model: function() {
        return users;
      }
    });
    
    App.UserRoute = Ember.Route.extend({
      model: function(params) {
        return users[params.user_id];
      }
    });
    
    App.EditUserRoute = Ember.Route.extend({
      model: function(params) {
        return users[params.user_id];
      },
      
      events: {
        save: function() {
          var user = this.modelFor('editUser');
          this.transitionTo('user', user);
        }
      }
    });
    
    
    
    
    
    
    var users = [
      {
        id: 0,
        first: 'Ryan',
        last: 'Florence',
        avatar: 'https://si0.twimg.com/profile_images/3123276865/5c069e64eb7f8e971d36a4540ed7cab2.jpeg'
      },
      {
        id: 1,
        first: 'Tom',
        last: 'Dale',
        avatar: 'https://si0.twimg.com/profile_images/1317834118/avatar.png'
      },
      {
        id: 2,
        first: 'Yehuda',
        last: 'Katz',
        avatar: 'https://si0.twimg.com/profile_images/3250074047/46d910af94e25187832cb4a3bc84b2b5.jpeg'
      }
    ];
  • 相关阅读:
    [组合][DP]luogu P3643 [APIO2016]划艇
    [倍增]luogu P4155 [SCOI2015]国旗计划
    [并查集][线段树]luogu P3273 [SCOI2011]棘手的操作
    pytest警告DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    docker-compose5分钟搭建wordpress博客网站
    Docker安装入门
    Windows10安装wget命令
    CRC (Cyclic Redundancy Check)
    Linux学习笔记
    Linux学习笔记
  • 原文地址:https://www.cnblogs.com/wangwenfei/p/emberjs_demo5.html
Copyright © 2020-2023  润新知