一次如何选择对象值?

时间:2019-03-18 13:45:47

标签: javascript

今天早上感觉很蠢。我尝试从返回的对象中选择一个值,但是每次选择该对象时,我都无法定义。

返回结果

child {
  Description: 'This is a wallet',
  Owners: [ '62766708' ],
  Balance: { Currency: 'GBP', Amount: 0 },
  Currency: 'GBP',
  FundsType: 'DEFAULT',
  Id: '62766709',
  Tag: null,
  CreationDate: 1552916375 }

功能

let resultToUpdate;
  if (userType == "natural") {
    resultToUpdate = await createNaturalUser(
      firstName,
      lastName,
      birthday,
      nationality,
      countryOfResidence,
      email
    );
    setTimeout(() => {
      console.log(resultToUpdate.child); // undefined
    }, 1000);
  }

如您所见,我什至尝试了setTimeout

编辑。这是createNaturalUser函数,扩展到createUserWallet。因此,上面的子对象是从第二个函数返回的

// ======================================================================
// CREATE NATURAL USER
// ======================================================================

export function createNaturalUser(
  firstName,
  lastName,
  birthday,
  nationality,
  countryOfResidence,
  email
) {
  var result = new Date(birthday).getTime().toString();
  var birthdayTimestamped = Number(result.slice(0, -3));
  var naturalUser = new mangoPay.models.UserNatural({
    FirstName: firstName, // First Name
    LastName: lastName, // Last Name
    Birthday: birthdayTimestamped, // timestamp
    Nationality: nationality, //
    CountryOfResidence: countryOfResidence, //
    Email: email // User email
  });

  return mangoPay.Users.create(naturalUser).then(function(response) {
    // Output the created user data to console
    return createUserWallet(response.Id);
  });
}

// ======================================================================
// CREATE USER WALLET
// ======================================================================

export function createUserWallet(owner) {
  var userWallet = new mangoPay.models.Wallet({
    Owners: [owner],
    Description: "This is a wallet",
    Currency: "GBP"
  });

  return mangoPay.Wallets.create(userWallet).then(function(response) {
    // console.log(response);
    return response;
  });
}

0 个答案:

没有答案