Ich bin ziemlich neu mit NodeJS und es verursacht offensichtlich einige Probleme, da die Dinge sehr asynchron sind.Wie synchron Instanz und erstellen in LoopBack
Ich versuche zu Instanzen zu finden, die verwendet werden müssen, um eine neue (Relation) zu erstellen: countryId
und clientId
.
Offensichtlich geschieht Dinge asynchron, so dass die Variablen nicht definiert sind. Wie mache ich es synchron?
Das ist mein Boot-Skript in LoopBack
module.exports = function(app) {
var Client = app.models.Client
var Country = app.models.Country
var BillingAddress = app.models.BillingAddress
Client.create([
{username: '[email protected]', email: '[email protected]', password: 'nasapassword'},
{username: '[email protected]', email: '[email protected]', password: 'nanapassword'}
], function(err, clients){
if(err) throw err
})
Country.findOne({where: {name: 'Spain'}},
function(err, country) {
if(err) throw err
}
)
Client.findOne({where: {email: '[email protected]'}},
function(err, client) {
if(err) throw err
}
)
BillingAddress.create([
{first_name: 'Jimbo', last_name: 'Juice', address_line_1: 'Loool street', postal_code: '23232', countryId: country.id, clientId: client.id}
], function(err, billingaddress) {
if(err) throw err
})
}
umgehen Just So enthalten i "async" und ich bekomme folgende Fehlermeldung, wenn ich den Code ausführen 'Typeerror: this.getDataSource ist kein function' – JavaCake
@JavaCake Wo sehen Sie' this.getDataSource verwenden ' ? –
Nirgendwo, es ist das erste Mal, dass ich das sehe. – JavaCake