Skip to content

Instantly share code, notes, and snippets.

@abuiles
Created September 10, 2014 14:56
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 abuiles/c5024772babe8daa10a1 to your computer and use it in GitHub Desktop.
Save abuiles/c5024772babe8daa10a1 to your computer and use it in GitHub Desktop.
Ember Starter Kit link-to with objet and id entering in model hook // source http://emberjs.jsbin.com/bupay/2
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="link-to with objet and id entering in model hook" />
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/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.7.0/ember.js"></script>
<style id="jsbin-css">
/* Put your CSS here */
html, body {
margin: 20px;
}
</style>
</head>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{render 'logs'}}
{{outlet}}
</script>
<script type="text/x-handlebars" id='logs'>
<h3>Logged</h3>
<a href="#" {{action 'clearLogs'}}>Clear Logs</a>
<ul>
{{#each}}
<li>{{this}}</li>
{{/each}}
</ul>
</script>
<script type="text/x-handlebars" data-template-name="index">
<p> Clicking in any of the following links won't hit the model hook on ShowRoute</p>
<ul>
{{#each item in model}}
<li>
{{link-to item.id 'show' item}}
</li>
{{/each}}
</ul>
<hr/>
<p> Clicking in any of the following routes will hit the model hook on ShowRoute</p>
<ul>
{{#each item in model}}
<li>
{{link-to item.id 'show' item.id}}
</li>
{{/each}}
</ul>
<hr/>
</script>
<script type="text/x-handlebars" data-template-name="show">
{{link-to 'Go to index' 'index'}}
<p>Model {{id}}</p>
</script>
<script id="jsbin-javascript">
App = Ember.Application.create();
var collection = [{id: 1}, {id:2}];
// Logging code based on Robert Jackson's http://jsbin.com/rolo/1/edit (rwjblue)
App.logs = Ember.ArrayProxy.create({content: []});
App.LogsController = Ember.ArrayController.extend({
content: App.logs,
actions: {
clearLogs: function(){
App.logs.clear();
}
}
});
App.Router.map(function() {
this.route('show', {path: '/show/:model_id'});
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return collection;
}
});
App.ShowRoute = Ember.Route.extend({
model: function(params) {
App.logs.pushObject('enter model hook');
return collection.findBy('id', params.model_id);
}
});
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<meta name="description" content="link-to with objet and id entering in model hook" />
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/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.7.0/ember.js"><\/script>
</head>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{render 'logs'}}
{{outlet}}
<\/script>
<script type="text/x-handlebars" id='logs'>
<h3>Logged</h3>
<a href="#" {{action 'clearLogs'}}>Clear Logs</a>
<ul>
{{#each}}
<li>{{this}}</li>
{{/each}}
</ul>
<\/script>
<script type="text/x-handlebars" data-template-name="index">
<p> Clicking in any of the following links won't hit the model hook on ShowRoute</p>
<ul>
{{#each item in model}}
<li>
{{link-to item.id 'show' item}}
</li>
{{/each}}
</ul>
<hr/>
<p> Clicking in any of the following routes will hit the model hook on ShowRoute</p>
<ul>
{{#each item in model}}
<li>
{{link-to item.id 'show' item.id}}
</li>
{{/each}}
</ul>
<hr/>
<\/script>
<script type="text/x-handlebars" data-template-name="show">
{{link-to 'Go to index' 'index'}}
<p>Model {{id}}</p>
<\/script>
</body>
</html>
</script>
<script id="jsbin-source-css" type="text/css">/* Put your CSS here */
html, body {
margin: 20px;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">App = Ember.Application.create();
var collection = [{id: 1}, {id:2}];
// Logging code based on Robert Jackson's http://jsbin.com/rolo/1/edit (rwjblue)
App.logs = Ember.ArrayProxy.create({content: []});
App.LogsController = Ember.ArrayController.extend({
content: App.logs,
actions: {
clearLogs: function(){
App.logs.clear();
}
}
});
App.Router.map(function() {
this.route('show', {path: '/show/:model_id'});
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return collection;
}
});
App.ShowRoute = Ember.Route.extend({
model: function(params) {
App.logs.pushObject('enter model hook');
return collection.findBy('id', params.model_id);
}
});
</script></body>
</html>
/* Put your CSS here */
html, body {
margin: 20px;
}
App = Ember.Application.create();
var collection = [{id: 1}, {id:2}];
// Logging code based on Robert Jackson's http://jsbin.com/rolo/1/edit (rwjblue)
App.logs = Ember.ArrayProxy.create({content: []});
App.LogsController = Ember.ArrayController.extend({
content: App.logs,
actions: {
clearLogs: function(){
App.logs.clear();
}
}
});
App.Router.map(function() {
this.route('show', {path: '/show/:model_id'});
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return collection;
}
});
App.ShowRoute = Ember.Route.extend({
model: function(params) {
App.logs.pushObject('enter model hook');
return collection.findBy('id', params.model_id);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment