如何使用Ember Data创建和恢复记录

时间:2016-07-11 06:16:10

标签: ember.js

我是ember-js的新手我无法使用此代码在ember-js中创建和恢复数据请帮助我。我没有在浏览器中获得任何输出。

<script type="text/x-handlebars" data-template-name="posts">
  <h2>Books Name and Author: </h2>
  {{#each post in controller}}
    <p><b>{{post.book}}</b></p>
    <p><i>{{post.author}}</i></p>
  {{/each}}
</script>

<script type="text/javascript">
  App = Ember.Application.create();

  //The store cache of all records available in an application
  App.Store = DS.Store.extend({
    //adapter translating requested records into the appropriate calls
    adapter: 'DS.FixtureAdapter'
  });

  App.ApplicationAdapter = DS.FixtureAdapter.extend();      

  App.Router.map(function() {
    //posts route
    this.resource('posts');
  });

  App.PostsRoute = Ember.Route.extend({
    model: function() {
      return this.store.find('post');
    }
  });
  App.Post = DS.Model.extend({
    //data Model
    //setting book and author attr as string
    book: DS.attr('string'),
    author: DS.attr('string')
  });

  //attach fixtures(sample data) to the model's class
  App.Post.FIXTURES = [{
    id: 1,
    book: 'Java',
    author: 'Balaguruswamy'},{
    id: 2,
    book: 'C++',
    author: 'Herbert Schildt'},{
    id: 3,
    book: 'jQuery',
    author: 'Ryan Benedetti'
  }];
</script>

0 个答案:

没有答案