2017-02-05 3 views
1

ich den Fehler danach weiterhin:Ember: Die Antwort auf store.query wird erwartet, dass ein Array sein, aber es war ein einziger Datensatz Fehler

Error: Assertion Failed: The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or use store.queryRecord to query for a single record.

Das ist mein Back-End:

router.route('/') 
.post(parseUrlencoded, parseJSON, function (request, response) { 
    var advancedStanding = new models.AdvancedStandings(request.body.advancedStanding); 
    advancedStanding.save(function (error) { 
     if (error) response.send(error); 
     response.json({advancedStanding: advancedStanding}); 
    }); 
}) 
.get(parseUrlencoded, parseJSON, function (request, response) { 
    //var l = parseInt(request.query.limit); 
    //var o = parseInt(request.query.offset); 
    var AdvancedStanding = request.query.filter; 
    if (!AdvancedStanding) { 
     models.AdvancedStandings.find(function (error, advancedStandings) { 
      if (error) response.send(error); 
      response.json({advancedStanding: advancedStandings}); 
     }); 
     //models.AdvancedStandings.paginate({}, { offset: o, limit: l }, 
     // function (error, students) { 
     //  if (error) response.send(error); 
     //  response.json({advancedStanding: advancedStandings.docs}); 
     // }); 
    } else { 
     //  if (Student == "residency") 
     models.AdvancedStandings.find({"studentInfo": AdvancedStanding.studentInfo}, function (error, advancedStandings) { 
      if (error) response.send(error); 
      console.log(advancedStandings); 
      response.json({advancedStudent: advancedStandings}); 

     }); 
    } 
}); 

das ist mein Frontend:

showStudentData: function (index) { 
this.set('currentStudent', this.get('studentsRecords').objectAt(index)); 
this.set('studentPhoto', this.get('currentStudent').get('photo')); 
var date = this.get('currentStudent').get('DOB'); 
var datestring = date.toISOString().substring(0, 10); 
this.set('selectedDate', datestring); 

var self2 = this; 
this.get('store').query('advanced-standing',{filter:{studentInfo:'585df32e0bf2ba5ea6951592'}}) 
.then(function(records123){ 
    console.log(records123); 
}); 

}

Hat jemand eine Idee, was passiert?

Danke.

Antwort

1

Die Funktion query erwartet mehrere Ergebnisse. so müssen Sie queryRecord

this.get('store').queryRecord('advanced-standing',{filter:{studentInfo:'585df32e0bf2ba5ea6951592'}}) 
.then(function(records123){ 
    console.log(records123); 
}); 

oder wickeln Sie Ihre Antwort in einem Arrayliteral

if (!AdvancedStanding) { 
    models.AdvancedStandings.find(function (error, advancedStandings) { 
     if (error) response.send(error); 
     response.json([{advancedStanding: advancedStandings}]); 
     // you were returning a single object 
     // note the array is now wrapping your previous result 

    }); 
    //models.AdvancedStandings.paginate({}, { offset: o, limit: l }, 
    // function (error, students) { 
    //  if (error) response.send(error); 
    //  response.json([{advancedStanding: advancedStandings.docs}]); 
       // you were returning a single object 
       // note the array is now wrapping your previous result 
    // }); 
} else { 
    //  if (Student == "residency") 
    models.AdvancedStandings.find({"studentInfo": AdvancedStanding.studentInfo}, function (error, advancedStandings) { 
     if (error) response.send(error); 
     console.log(advancedStandings); 
     response.json([{advancedStudent: advancedStandings}]); 
     // you were returning a single object 
     // note the array is now wrapping your previous result 
    }); 
} 
+0

ich es von Abfrage zu queryRecord jedoch geändert verwenden, die console.log (records123) den Wert null zurück. – Jackie

+0

Sind Sie sicher, dass ein Student gefunden wird? – TheRealMrCrowley

+0

Was zeigen Ihre Serverprotokolle? – TheRealMrCrowley

Verwandte Themen