Emberjs / data Object“没有方法'_create'”

时间:2012-09-06 04:49:01

标签: ember.js ember-data

我正在尝试使用Ember和Ember / Data来显示从REST API返回的简单JSON 这是我的js:

window.ManageClients = Em.Application.create();

ManageClients.store = DS.Store.create({
  revision: 4,
  adapter: DS.RESTAdapter.create({
    bulkCommit: false,
    namespace: "api"
  })
});

ManageClients.Client = DS.Model.extend({
  url: '/clients',
  name: DS.attr('string'),
  slug: DS.attr('string'),
  programs: DS.attrArray('string'),
  selfserve: DS.attrArray('string')
});

ManageClients.Clients = ManageClients.store.findAll(ManageClients.Client);

ManageClients.ClientsView = Em.View.create({
  templateName: 'client-template'
});

ManageClients.ClientsView.appendTo('#ManageClients');

我的模板:

<div id="ManageClients">
    <script type="text/x-handlebars" data-template-name="client-template">
        <ul>
            {{#each ManageClients.Clients}}
            <li>
                {{#if isLoaded}}
                    Client:{{name}}
                {{else}}
                    Loading...
                {{/if}}
            </li>
            {{/each}}
        </ul>
    </script>
</div>
<script language="javascript" src="/js/manageClients.js"></script>

错误:

Uncaught TypeError: Object ManageClients.Client has no method '_create' ember-data.js:1811
DS.Store.Ember.Object.extend.materializeRecord ember-data.js:1811
DS.Store.Ember.Object.extend.findByClientId ember-data.js:1204
DS.RecordArray.Ember.ArrayProxy.extend.objectAtContent ember-data.js:45
Ember.wrap.newFunc ember.js:949
Ember.ArrayProxy.Ember.Object.extend.objectAt ember.js:9204
Ember.wrap.newFunc ember.js:949
Ember.Array.Ember.Mixin.create.arrayContentDidChange ember.js:6946
Ember.ArrayProxy.Ember.Object.extend.arrangedContentArrayDidChange ember.js:9227
invokeAction ember.js:3174
iterateSet ember.js:3156
sendEvent ember.js:3273
Ember.Array.Ember.Mixin.create.arrayContentDidChange ember.js:6941
Ember.Mixin.create.replace ember.js:9616
Ember.MutableArray.Ember.Mixin.create.insertAt ember.js:7410
Ember.MutableArray.Ember.Mixin.create.pushObject ember.js:7458
DS.Store.Ember.Object.extend.updateRecordArray ember-data.js:1618
DS.Store.Ember.Object.extend.updateRecordArrays.manyArrays ember-data.js:1586
DS.Store.Ember.Object.extend.updateRecordArrays ember-data.js:1584
DS.Store.Ember.Object.extend.load ember-data.js:1744
DS.Store.Ember.Object.extend.loadMany ember-data.js:1763
DS.RESTAdapter.DS.Adapter.extend.findAll.ajax.success ember-data.js:4580
f.Callbacks.o jquery-1.7.2.min.js:2
f.Callbacks.p.fireWith jquery-1.7.2.min.js:2
w jquery-1.7.2.min.js:4
f.support.ajax.f.ajaxTransport.send.d

并且:

Uncaught TypeError: Object ManageClients.Client has no method '_create' ember-data.js:1811
DS.Store.Ember.Object.extend.materializeRecord ember-data.js:1811
DS.Store.Ember.Object.extend.findByClientId ember-data.js:1204
DS.RecordArray.Ember.ArrayProxy.extend.objectAtContent ember-data.js:45
Ember.wrap.newFunc ember.js:949
Ember.ArrayProxy.Ember.Object.extend.objectAt ember.js:9204
Ember.wrap.newFunc ember.js:949
Ember.CollectionView.Ember.ContainerView.extend.arrayDidChange ember.js:14651
Ember.CollectionView.Ember.ContainerView.extend._contentDidChange ember.js:14582
Ember.CollectionView.Ember.ContainerView.extend.init ember.js:14553
Ember.wrap.newFunc ember.js:949
Ember._Metamorph.Ember.Mixin.create.init ember.js:18038
Ember.wrap.newFunc ember.js:949
Class ember.js:8259
Ember.Mixin.create.create ember.js:8398
Ember.View.Ember.Object.extend.createChildView ember.js:13320
Ember.View.states.inBuffer.appendChild ember.js:13762
Ember.View.Ember.Object.extend.invokeForState ember.js:12402
Ember.View.Ember.Object.extend.appendChild ember.js:13199
EmberHandlebars.ViewHelper.Ember.Object.create.helper ember.js:18873
(anonymous function) ember.js:19030
(anonymous function) ember.js:19229
(anonymous function) ember.js:19366
(anonymous function)
(anonymous function) handlebars.js:1879
Ember.View.Ember.Object.extend.render ember.js:12368
Ember.View.Ember.Object.extend.renderToBuffer ember.js:13017
Ember.View.Ember.Object.extend.createElement ember.js:12814
Ember.View.states.preRender.insertElement ember.js:13702
Ember.View.Ember.Object.extend.invokeForState ember.js:12402
invoke ember.js:3377
iter ember.js:3424
RunLoop.flush ember.js:3480
RunLoop.end ember.js:3396
Ember.run.end ember.js:3588
autorun

1 个答案:

答案 0 :(得分:0)

此错误已在更高版本的ember中解决,不再相关。