Created
April 1, 2014 09:58
-
-
Save yoga1290/9911227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: Helvetica, Arial, sans-serif; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> | |
<script src="http://builds.emberjs.com/canary/ember-data.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script type="text/x-handlebars" data-template-name="index"> | |
{{#each}} | |
{{#link-to 'post' id}} | |
post#{{id}} | |
{{/link-to}} | |
<br> | |
{{/each}} | |
<br><br> | |
{{#link-to 'post' 100}} | |
Special post! | |
{{/link-to}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="post"> | |
{{post}} | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App = Ember.Application.create({ | |
LOG_TRANSITIONS: true | |
//, | |
// LOG_TRANSITIONS_INTERNAL: true, | |
// LOG_VIEW_LOOKUPS: true, | |
// LOG_ACTIVE_GENERATION: true | |
}); | |
App.Router.map(function() { | |
this.route('post', { path: ':postId' }); | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
model: function() { | |
console.log("IndexRoute.model: store.findAll"); | |
return this.store.findAll('post'); | |
} | |
}); | |
App.Post=DS.Model.extend({ | |
postId: DS.attr('number'), | |
post:DS.attr('string') | |
}); | |
App.PostRoute= Ember.Route.extend({ | |
model:function(params){ | |
return this.store.find('post',params.postId); | |
} | |
}); | |
App.ApplicationAdapter = DS.RESTAdapter.extend({ | |
ajax: function(url,type,hash) | |
{ console.log("RESTAdapter.ajax("+url+","+type+",hash)"); | |
console.log(hash); | |
if(url.indexOf('id=undefined')==-1) | |
return {postId:1,post:'Mocking Post from RESTAdapter.ajax'}; | |
return [{postId:1,post:'Mocking Post from RESTAdapter.ajax'},{postId:2,post:'Mocking Post'}]; | |
}, | |
buildURL:function(type,id){ | |
console.log("RESTAdapter.buldURL:"); | |
console.log("from:"+this._super(type,id)); | |
console.log("to:"+"/MyGETCommand?type="+type+"&id="+id); | |
return "/MyGETCommand?type="+type+"&id="+id; | |
} | |
}); | |
App.PostSerializer = DS.RESTSerializer.extend({ | |
extractArray: function(store, type, payload, id, requestType) { | |
console.log("Payload from Application-RESTAdapter to Port-RESTSerializer.extractArray:"); | |
console.log(payload); | |
console.log("Returned payload by Port-RESTSerializer.extractArray:"); | |
console.log([{id:1,postId:1,post:'Mocking Post from PostSerializer.extractArray'}]); | |
return this._super(store, type, { posts: [{id:1,postId:1,post:'Mocking Post from PostSerializer.extractArray'}] }, id, requestType); | |
}, | |
extractSingle: function(store, type, payload, id, requestType){ | |
console.log("Payload from Application-RESTAdapter to Port-RESTSerializer.extractSingle:"); | |
console.log(payload); | |
console.log("Returned payload by Port-RESTSerializer.extractSingle:"); | |
console.log({id:100,postId:100,post:'Mocking Post from PostSerializer.extractSingle'}); | |
return this._super(store, type, { posts: {id:1,postId:1,post:'Mocking Post from PostSerializer.extractSingle'} }, id, requestType); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment