课程表

Ember.js 基础

Ember.js 对象模型

Ember.js handlebars模板

Ember.js 路由

Ember.js 组件

Ember.js 控制器

Ember.js 模型

Ember.js 测试

工具箱
速查手册

设置记录到Store

当前位置:免费教程 » JS/JS库/框架 » Ember.js

EmberStore就像一个缓存池,用户提交的数据以及从服务器获取的数据会首先保存到Store。如果用户再次请求相同的数据会直接从Store中获取,而不是发送HTTP请求去服务器获取。

当数据发生变化,数据首先更新到Store中,Store会理解更新到其他页面。所以当你改变Store中的数据时,会立即反应出来,比如上一篇更新记录小结,当你修改article的数据时会立即反应到页面上。

1,push()方法

你可以调用push()方法一次性把多条数据保存到Store中。比如下面的代码:

  1. // app/routes/application.js
  2. import Ember from 'ember';
  3. export default Ember.Route.extend({
  4. model: function() {
  5. this.store.push({
  6. data: [
  7. {
  8. id: 1,
  9. type: 'album',
  10. attributes: { // 设置model属性值
  11. title: 'Fewer Moving Parts',
  12. artist: 'David Bazan'
  13. songCount: 10
  14. },
  15. relationships: {} // 设置两个model的关联关系
  16. },
  17. {
  18. id: 2,
  19. type: 'album',
  20. attributes: { // 设置model属性值
  21. title: 'Calgary b/w I Can\'t Make You Love Me/Nick Of Time',
  22. artist: 'Bon Iver',
  23. songCount: 2
  24. },
  25. relationships: {} // 设置两个model的关联关系
  26. }
  27. ]
  28. });
  29. }
  30. });

注意type属性值必须是模型的属性名字。attributes哈希里的属性值与模型里的属性对应。

本篇不是很重要,就简单提一提,如有兴趣请看Pushing Records Into The Store的详细介绍。

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号