Share
Embed
Transcript
42 slides
-
Ember.js Ember.js Ember.js Ember.js Ember.js Ember.js 2012-07-11 Vol.31 )5.-ͱ͔ษڧձ Playing
Playing PLaying Playing Playing With With With With With -
Yuya Saito Yuya Saito Yuya Saito @CSSRADAR @CSSRADAR @CSSRADAR @cyberagent
@cyberagent @cyberagent -
NO Agenda NO Agenda NO Agenda NO Agenda NO Agenda
Just Get To know Just Get To Know Just Get To Know Just Get To KNOW Just Get To Know Ember.js Ember.js Ember.js Ember.js Ember.js -
“Ember is a JavaScript framework for creating ambitious web applications
that eliminates boilerplate and provides a standard application architecture.” - emberjs.com/documentation -
MyApp.president = Ember.Object.create({ name: "Barack Obama" }); MyApp.country = Ember.Object.create({
// ϓϩύςΟ໊ͷ࠷ޙʹ'Binding'ͱ༩͢Δͱ // presidentNameʹόΠϯσΟϯάΛੜ͢Δɻ presidentNameBinding: 'MyApp.president.name' }); // Ember͕όΠϯσΟϯάΛղܾͨ͠ޙ... MyApp.country.get('presidentName'); // ݁Ռ: "Barack Obama" -
MyApp.president = Ember.Object.create({ firstName: "Barack", lastName: "Obama", fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName'); // ҎԼͷϑϥάʹΑͬͯؔΛϓϩύςΟͷΑ͏ʹѻ͏ }.property() }); MyApp.president.get('fullName'); // ݁Ռ: "Barack Obama" -
<!doctype html> <html> <head> <title>Tweets</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link
rel="stylesheet" href="styles.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/ jquery.min.js"></script> <script src="http://cloud.github.com/downloads/emberjs/ember.js/ ember-0.9.6.min.js"></script> <script src="app.js"></script> </head> <body> <script type="text/x-handlebars"> <div id="frm"> <b>Load Tweets for: </b> </div> <div id="content"> <div id="recent"> <h3>Recent Users</h3> </div> <div id="tweets"> <h3>Tweets</h3> </div> </div> </script> </body> </html> -
<body> <script type="text/x-handlebars"> <div id="frm"> <b>Load Tweets for: </b> </div>
<div id="content"> <div id="recent"> <h3>Recent Users</h3> </div> <div id="tweets"> <h3>Tweets</h3> </div> </div> </script> </body> -
App.tweetsController = Em.ArrayController.create({ content: [], username: '', loadTweets: function() {
var me = this; var username = me.get("username"); alert(username); if ( username ) { var url = 'http://api.twitter.com/1/statuses/ user_timeline.json' url += '?screen_name= %@&callback=?'.fmt(me.get("username")); // push username to recent user array App.recentUsersController.addUser(username); } } }); "QQUXFFUT$POUSPMMFS -
App.recentUsersController = Em.ArrayController.create({ content: [], addUser: function(name) { if (
this.contains(name) ) this.removeObject(name); this.pushObject(name); }, removeUser: function(view){ this.removeObject(view.context); }, searchAgain: function(view){ App.tweetsController.set('username', view.context); App.tweetsController.loadTweets(); }, reverse: function(){ return this.toArray().reverse(); }.property('@each') }); "QQSFDFOU6TFST$POUSPMMFS -
<ol> {{#each App.recentUsersController.reverse}} <li> <a href="#" title="view again" {{action "searchAgain"
target="App.recentUsersController"}} >{{this}}</a> - <a href="#" title="remove" {{action "removeUser" target="App.recentUsersController"}} >X</a> </li> {{/each}} </ol> อଘͨ͠ݕࡧΩʔϫʔυͷදࣔ -
App.Tweet = Em.Object.extend({ avatar: null, screen_name: null, text: null, date:
null }); 5XFFUTΛऔಘ͢ΔPCKFDU -
$.getJSON(url,function(data){ me.set('content', []); $(data).each(function(index,value){ var t = App.Tweet.create({ avatar: value.user.profile_image_url,
screen_name: value.user.screen_name, text: value.text, date: value.created_at }); me.pushObject(t); }) }); 5XFFUTΛऔಘ͢Δ"KBY -
<ul> {{#each App.tweetsController}} <li> <img {{bindAttr src="avatar"}} /> <span>{{date}}</span> <h3>{{screen_name}}</h3>
<p>{{text}}</p> </li> {{/each}} </ul> 5XFFUTΛදࣔ͢Δ5FNQMBUF -
What IS Ember.js? What Is Ember.js? What is Ember.js? MVC:
Ember.js MVC: Ember.js MVC: Ember.js features features features Gist of Ember.js Gist of Ember.js Gist of Ember.js -
“Ember’s philosophy is that by eliminating trivial choices and making
the answers conventional, you can focus your energy on non-trivial problems.” - Tom Dale -
READ the Docs READ the Docs READ the Docs READ
the Docs READ the Docs