Skip to content

Instantly share code, notes, and snippets.

@gutenye
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gutenye/9797474 to your computer and use it in GitHub Desktop.
Save gutenye/9797474 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Ember Hello</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.4.0/ember.min.js"></script>
</head>
<body>
<script type="text/x-handlebars" data-template-name="application">
{{#link-to 'index'}}Index{{/link-to}} {{#link-to 'about'}}About{{/link-to}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h1>INDEX {{name}}</h1>
</script>
<script type="text/x-handlebars" data-template-name="about">
<h1>About</h1>
</script>
<script type="text/javascript">
window.App = Ember.Application.create()
App.Router.map(function() {
this.route("about")
})
App.IndexRoute = Ember.Route.extend({
model: function() {
return Ember.Object.create({name: 'HAHA'})
}
})
</script>
</body>
</html>
@gutenye
Copy link
Author

gutenye commented Mar 27, 2014

Install

1. 在 D:/ember 里面
2. 保存上面的文件 a.html
3. 安装ember

$ npm install -g bower
$ bower install ember

4. 在浏览器里面打开a.html

@gutenye
Copy link
Author

gutenye commented Mar 27, 2014

比如你要一个 '/feng' URL

<!-- 先一个feng模板 -->
<script type="text/x-handlebars" data-template-name="feng">
<h1>hi {{name}}</h1>
</script>

<script type="text/javascript">
// 再定义一个route
App.Router.map(function() {
  this.route('feng')
})

// 然后给数据
App.FengRoute = Ember.Route.extend({
  mode: function() {
    return Ember.Object.create({name: 'feng'})
 }
})
</script>

这个时候访问 'a.html#/feng' 就出现一个页面了

@gutenye
Copy link
Author

gutenye commented Mar 27, 2014

feng -> FengRoute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment