Skip to content

Instantly share code, notes, and snippets.

@yoga1290
Last active May 11, 2018 10:44
Show Gist options
  • Save yoga1290/9805682 to your computer and use it in GitHub Desktop.
Save yoga1290/9805682 to your computer and use it in GitHub Desktop.
Dynamic Segments in Ember.JS
body {
font-family: Helvetica, Arial, sans-serif;
}
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<script type="text/x-handlebars" data-template-name="index">
{{#linkTo "post" 0}}
1st post
{{/linkTo}}
<br>
{{#linkTo "post" 1}}
2nd post
{{/linkTo}}
</script>
<script type="text/x-handlebars" data-template-name="post">
data={{text}}
</script>
</body>
</html>
App = Ember.Application.create({
LOG_TRANSITIONS: true});
App.Router.map(function() {
this.resource('post', { path: ':postId' });
});
App.myArray=[
{
text:"My 1st post"
},
{
text:"My 2nd post1"
}];
App.PostRoute = Ember.Route.extend({
model: function(params) {
return App.myArray[params.postId];
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment