<!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'
}
];

Ember.js demo5的更多相关文章

  1. MVC、MVP、MVVM、Angular.js、Knockout.js、Backbone.js、React.js、Ember.js、Avalon.js、Vue.js 概念摘录

    注:文章内容都是摘录性文字,自己阅读的一些笔记,方便日后查看. MVC MVC(Model-View-Controller),M 是指业务模型,V 是指用户界面,C 则是控制器,使用 MVC 的目的是 ...

  2. 【前端】Ember.js学习笔记

    Model 在默认情况下,model钩子返回的值,会设置为关联的控制器的model属性.例如,如果App.PostsRoute通过model钩子返回了一个对象,这个对象会设置为App.PostsCon ...

  3. Ember.js 的视图层

    本指导会详尽阐述 Ember.js 视图层的细节.为想成为熟练 Ember 开发者准备,且包 含了对于入门 Ember 不必要的细节. Ember.js 有一套复杂的用于创建.管理并渲染连接到浏览器 ...

  4. Ember.js入门教程、博文汇总

    第一章 对象模型 Ember.js 入门指南——类的定义.初始化.继承 Ember.js 入门指南——类的扩展(reopen) Ember.js 入门指南——计算属性(compute properti ...

  5. 点燃圣火! Ember.js 的初学者指南

    现在,到处都可以看到复杂的 JavaScript 应用程序. 由于这些应用程序变得越来越复杂,一长串的 jQuery 回调语句,或者通过应用程序在各个点执行不同的函数调用,这些都变得无法再让人接受. ...

  6. Ember.js之动态创建模型

    本人原文地址发布在:点击这里 What problem did we meet? As ember document suggestion, we may define a model as a st ...

  7. Ember.js实现单页面应用程序

    1.1.1 摘要 单页应用程序 (SPA) 是加载单个HTML 页面并在用户与应用程序交互时动态更新该页面的Web应用程序. SPA使用AJAX和HTML5创建流畅且响应迅速的Web应用程序,不会经常 ...

  8. Ember.js系列文章

    JS前端框架之Ember.js系列文章 本文为文章索引,主要是罗列Ember.js的相关文章便于阅读. 相关演示代码:github for free. 基础篇 1. EmberJs之What|Why| ...

  9. 【JavaScript】前端开发框架三剑客—AngularJS VS. Backone.js VS.Ember.js

    摘要:透过对Github,StackOverflow,YouTube等社区进行数据收集后可知,AngularJS在各大主流社区中都是最受欢迎的,Backbone.js与Ember.js则不相伯仲.本文 ...

随机推荐

  1. String类中toCharArray()方法的用法

    该方法的作用是返回一个字符数组,该字符数组中存放了当前字符串中的所有字符 eg:  public class class6_3 { public static void main(String arg ...

  2. 日志记录类LogHelper

    开源日志log4net使用起来很方便,但是项目中不让用,所以自己重写了一个类,用来记录日志,比较简单. 1.首先是可以把日志分成多个类型,分别记录到不同的文件中 /// <summary> ...

  3. 从零开始部署小型企业级虚拟桌面 -- Vmware Horizon View 6 For Linux VDI -- 结构规划

    环境说明 注,本套环境所用机器全部是64位的. 管理服务器载体:安装win7操作系统,通过VMware Workstation安装4台虚拟机,用作vCenter,Connection Server,D ...

  4. Ajax的概述与实现过程

    一.ajax概述 1.Ajax是Asynchronous([ə'sɪŋkrənəs) JavaScript XML的简写,不是一门新技术,而是对现有技术的综合利用.这一技术能够向服务器请求额外数据而无 ...

  5. 嵌入式系统关机/Embeded System PowerOff HowTo?

    REFER: 嵌入式Linux实现关机命令 REFER: Embedded File System and power-off REFER: kernel/reboot.c REFER: PowerO ...

  6. indeed 第二次笔试题

    1. Maximal Values 很简单,从前往后扫,找满足的,O(n),很容易就过掉了. maxn = 100. 没啥难点. 2. Bi-gram 用map统计个数,从前往后扫,每2个字符作为一个 ...

  7. Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Jav ...

  8. Trie,HDU1875world puzzle

    附上代码 #include<iostream> #include<cstdio> #include<string> #include<cstring> ...

  9. wifidog编译到openwrt

    首先敲一下 cd 命令,定位到自己的用户目录, 然后 mkdir openwrt 新建一个openwrt文件夹,然后开始装openwrt的编译用到的工具, sudo apt-get install g ...

  10. JSONP(跨域请求) —— 一种非官方跨域数据交互协议

    1.JSONP的作用 由于同源策略的限制,XmlHttpRequest只允许请求当前源(域名.协议.端口)的资源,为 了实现跨域请求,可以通过script标签实现跨域请求,然后再服务器端输出JSON数 ...