May 09, 2021 Ember.js Reference documents
Ember's Store is like a cache pool, where data submitted by the user and data obtained from the server is first saved to the Store. If the user requests the same data again, it will get it directly from store instead of sending an HTTP request to the server.
When the data changes and the data is first updated to the Store, the Store understands that the update is to another page.
So when you change the data in the Store, you react immediately, such as the last update record synth, and when you modify the data in
article
it reacts immediately to the page.
You can
push()
method to save multiple data to the Store at once.
For example, the following code:
// app/routes/application.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
this.store.push({
data: [
{
id: 1,
type: 'album',
attributes: { // 设置model属性值
title: 'Fewer Moving Parts',
artist: 'David Bazan'
songCount: 10
},
relationships: {} // 设置两个model的关联关系
},
{
id: 2,
type: 'album',
attributes: { // 设置model属性值
title: 'Calgary b/w I Can\'t Make You Love Me/Nick Of Time',
artist: 'Bon Iver',
songCount: 2
},
relationships: {} // 设置两个model的关联关系
}
]
});
}
});
Note:
The
type
value must be the property name of the model.
attributes
hash's property value corresponds to the property in the model.
This article is not very important, just mention it simply, if you are interested in seeing the pushing Records Into The Store in detail.
The full code of the blog post
is placed in Github
(the blog post has been modified several times, and the code on the blog post may be different from the github code, but the impact is small!). I
f you think the blog post is a bit useful to you, please give me a star on the
star
project.
Yours is definitely the biggest motivation for me!!