OSDN Git Service

Regular updates
[twpd/master.git] / ember.md
1 ---
2 title: Ember.js
3 category: JavaScript libraries
4 ---
5
6 {% raw %}
7
8 ### Routes
9
10     App.Router.map(function() {
11       this.resource('trips', function() {
12           this.route('item', { path: '/:trip_id' });
13       });
14
15       this.route('upcoming');
16       this.route('about', { path: '/about' });
17       this.route('schedules');
18       this.route('history');
19       this.route('post');
20     });
21
22 ### A route
23
24     App.IndexRoute = Ember.Route.extend({
25       setupController: function(controller) {
26         controller.set('title', 'my app');
27         // <h1>{{title}}</h1>
28       },
29
30       setupController: function(controller, model) {
31         controller.set("model", model);
32         this.controllerFor('topPost').set('model', model);
33       },
34
35       model: function(params) {
36         return this.store.find('posts');
37         return this.store.find('post', params.post_id);
38       },
39       
40       serialize: function(model) {
41         // this will make the URL `/posts/foo-post`
42         return { post_slug: model.get('slug') };
43       }
44     });
45
46 ### View
47
48     App.InfoView = Ember.View.extend({
49       templateName: 'input',  /* optional */
50
51       fooName: "Hello"  /* {{ view.fooName }} */
52
53       click: function(e) {
54         "I was clicked";
55       }
56
57     });
58
59 ### markup
60
61     <img {{bindAttr src="avatarURL"}}>
62     <button {{action follow}}>
63
64 Value binding:
65
66     {{view Ember.TextField class="input block" valuebinding="emailAddresses"}}
67
68 Actions:
69
70     <button {{action invite emailAddresses}}>Invite></button>
71
72     <a href="#" {{action set "isEditingContacts" true target="view"}} 
73
74 {% endraw %}