EmberJS自定义路线动作

时间:2014-02-22 03:15:02

标签: javascript jquery ember.js

我有一个jsfiddle示例,我无法应用FixtureAdapater。我很糟糕,我正在努力学习,但我无法让它发挥作用。非常感谢任何帮助,非常感谢你

HTML

<body>

  <script type="text/x-handlebars" data-template-name="MessageManager">
    <ul>
    {{#each item in model}}
      <li>{{item}}</li>
    {{/each}}
    </ul>
  </script>

</script>

</body>

JAVASCRIPT

window.MessageManager = Ember.Application.create();

MessageManager.Store = DS.Store.extend({
    revision: 13,
    adapter: DS.FixtureAdapter.create()
});

MessageManager.Router.map(function() {
this.resource('MessageManager',{path :'/'});
});

MessageManager.MessageManagerRoute = Ember.Route.extend({
model: function() {
var x = this.store.find('Message');
}
});

MessageManager.Message = DS.Model.extend({
id:DS.attr('id'),
SendingPhoneNumber : DS.attr('string'),
ReceivingPhoneNumber : DS.attr('string'),
DateReceived : DS.attr('date')});

MessageManager.Message.FIXTURES = [
{
id:1, 
SendingPhoneNumber :'555 555 9219',
ReceivingPhoneNumber :'555 555 1646',
Message : 'Why Do i have a 5 dollar charge on my phone bill',
DateReceived :'2014-02-21'
},
{
id:2,
 SendingPhoneNumber :'555 555 9219',
ReceivingPhoneNumber :'555 555 1678',
DateReceived :'2014-02-18'
}];

1 个答案:

答案 0 :(得分:1)

jsbin上有一些固定版本的错误。我不确定你正在使用哪个版本的ember-data,但是ember-data改变了你设置适配器的方式,你设置工厂而不是实例:

adapter: DS.FixtureAdapter

而不是:

adapter: DS.FixtureAdapter.create()

此外,无需在模型定义上设置id属性,并且脚本元素还有一个额外的结束标记。

希望这会有所帮助。