2014-02-25 10:32:14 +00:00
|
|
|
---
|
|
|
|
title: Ember.js
|
2017-08-28 19:56:17 +00:00
|
|
|
category: JavaScript libraries
|
2023-03-14 01:52:21 +00:00
|
|
|
tags: [Archived]
|
|
|
|
archived: This sheet describes an older version of Ember.
|
2014-02-25 10:32:14 +00:00
|
|
|
---
|
|
|
|
|
2017-08-28 15:51:51 +00:00
|
|
|
{% raw %}
|
|
|
|
|
2014-02-25 10:32:14 +00:00
|
|
|
### Routes
|
|
|
|
|
2021-09-10 03:34:37 +00:00
|
|
|
Router.map(function() {
|
|
|
|
this.route('trips', function() {
|
|
|
|
this.route('item', { path: '/:tripId' });
|
2014-02-25 10:32:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.route('upcoming');
|
2021-09-10 03:34:37 +00:00
|
|
|
this.route('about', { path: '/aboutus' });
|
2014-02-25 10:32:14 +00:00
|
|
|
this.route('schedules');
|
|
|
|
this.route('history');
|
2021-09-10 03:34:37 +00:00
|
|
|
this.route('post', { path: '/post/:postId' });
|
2014-02-25 10:32:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
### A route
|
|
|
|
|
2021-09-10 03:34:37 +00:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
|
|
|
|
export default PostRoute extends Route {
|
|
|
|
model({ postId }) {
|
|
|
|
// Post will be accessible as `this.model` in the controller
|
|
|
|
// or `{{@model}}` in the template.
|
|
|
|
return this.store.find('post', postId);
|
2014-02-25 10:32:14 +00:00
|
|
|
}
|
2021-09-10 03:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
### Component
|
|
|
|
|
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
|
|
|
|
|
|
|
export default PostEditor extends Component {
|
|
|
|
@tracked title;
|
|
|
|
|
|
|
|
get fullTitle() {
|
|
|
|
return `Post: ${title}`;
|
2014-02-25 10:32:14 +00:00
|
|
|
}
|
2021-09-10 03:34:37 +00:00
|
|
|
|
|
|
|
titleUpdate(event) {
|
|
|
|
this.title = event.target.value;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2021-09-10 03:34:37 +00:00
|
|
|
### Template
|
2014-03-22 04:04:21 +00:00
|
|
|
|
2021-09-10 03:34:37 +00:00
|
|
|
<div ...attributes>
|
|
|
|
<label for="title">Title</label>
|
|
|
|
<input
|
|
|
|
id="title"
|
|
|
|
value={{@post.title}}
|
|
|
|
{{on 'input' this.updateTitle}}
|
|
|
|
/>
|
2014-03-22 04:04:21 +00:00
|
|
|
|
2021-09-10 03:34:37 +00:00
|
|
|
<p>
|
|
|
|
{{this.fullTitle}}
|
|
|
|
</p>
|
|
|
|
</div>
|
2014-03-22 04:04:21 +00:00
|
|
|
|
2021-09-10 03:34:37 +00:00
|
|
|
Invoking the component:
|
2014-03-22 04:04:21 +00:00
|
|
|
|
2021-09-10 03:34:37 +00:00
|
|
|
<PostEditor class='my-post' @post={{@model}} />
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 15:51:51 +00:00
|
|
|
|
|
|
|
{% endraw %}
|