Assertion failed: No model was found for '0

2019-08-06 11:02发布

问题:

I'm getting the error with the following code:

App.SearchRoute = Ember.Route.extend({
    model: function(){
        return this.store.find('cabinets')
    }
});
App.SearchAdapter = DS.DjangoRESTAdapter.extend({
   namespace: 'rest_framework'
});

I created the model but its not formatting the JSON correctly and I'm not sure what I am doing wrong.

Also if I pump in this code instead:

App.Store = DS.DjangoRESTStore.extend({
 adapter: DS.DjangoRESTAdapter.create({
    namespace: "rest_framework"
 }),
 revision: 12
 });

I get an error on the extend method....

Here is my JSON return from a test.

0: {id:1, cabinet_name:HR Department, cabinet_security:1, status:1}

回答1:

What version of Ember Data are you using? If it's a 1.0, you need to use the version described here (https://github.com/emberjs/data/blob/master/TRANSITION.md) and not define the store like so. I'm pretty sure you were originally trying that though. Additionally, is your JSON really not coming with quotes around HR Department?

App.CabinetAdapter = DS.DjangoRESTAdapter.extend({
  namespace: 'rest_framework'
});


回答2:

Here is what chrome shows me

DEBUG: ------------------------------- ember.js:3231
DEBUG: Ember      : 1.3.0-beta.1+canary.628071a4 ember.js:3231
DEBUG: Ember Data : 1.0.0-beta.4+canary.e7996c4d ember.js:3231
DEBUG: Handlebars : 1.0.0 ember.js:3231
DEBUG: jQuery     : 1.10.2 ember.js:3231
DEBUG: ------------------------------- 

Oh yes there is quotes around I didnt notice that those didnt copy over from the debugger.

Here is what I have listed and now for some reason it works

DS.DjangoRESTSerializer = DS.RESTSerializer.extend();
DS.DjangoRESTAdapter = DS.RESTAdapter.extend({
      defaultSerializer: "DS/djangoREST"
});

App.Store = DS.Store.extend({
        revision: 12,
        adapter: DS.DjangoRESTAdapter.create()
});
App.SearchAdapter = DS.DjangoRESTAdapter.extend({
    namespace: 'rest_framework'
});