Reputation: 4613
Conclusion: It was a typo.
I'm trying something something which seems simple, but I think I'm missing out on something fundamental to Vue. I have an id, and an object with once child property that contains an object with that id. When I loop through the object properties to compare the id, it is false. When I log the values that were compared in the else statement after the comparison, they appear to be identical in the console log.
Whatever I try it, I keep ending up on the "bad package" line. The console shows me that the object property is there and that the id of the object at that property is correct. It looks like:
bad package c5186ae5-1558-490b-a9d2-5fc19c0a736d !== c5186ae5-1588-490b-a9d2-5fc19c0a736d
I suspect it is something to do with observables in Vue, even though the log doesn't show anything as an observable.
What's the right way to do what I'm trying to do?
// newVal = '29e51254-a88a-4309-92bc-ad1d0cda1427'
collectionIdForVerification (newVal) {
const parcelId = this.$store.state.parcels.collectionIdForVerification
// this print the object, it looks good
console.log('Parcels are ', this.requestedParcelsForCollection)
console.log('local parcels are ', this.local.parcels)
const loParcOb = JSON.parse(JSON.stringify(this.local.parcels))
console.log('local parcels are ', loParcOb)
console.log('does the parcel for ', newVal, ' exist? ', this.local.parcels[newVal])
if (newVal) {
const packages = loParcOb
console.log('lets check ', packages, ' for ', parcelId)
const rightPackage = loParcOb[parcelId]
console.log('right package is ', rightPackage)
for (let x in loParcOb) {
let ob = loParcOb[x]
console.log('object: ', ob)
if (ob.id.toString() === parcelId) {
console.log('good pagage ', ob)
} else {
// this shows me that the two compared things are equal
console.log('bad package ', ob.id.toString(), ' !== ', parcelId)
}
}
}
}
Object:
// object
{
displayImage: "https://static.xxxx.co/couriers/dhl/dhl_detail.png"
expiration: 1573486971237
id: "29e51254-a88a-4309-92bc-ad1d0cda1427"
name: "MacBook from YYYY"
passcode: ""
recipient: {xxxId: "0cbf8068-a286-49c5-bdf7-7509ac953b5f", yyyId: "b925b763-992e-4ad3-98b1-ba8fba2ef37e"}
sender: {xxxId: "9cad32d0-6724-414b-a686-a8e133db2225", yyyId: "997eeab8-a698-4027-93d3-43ca5d6ee121"}
slotHeight: 2
startingSlot: 37
status: "IN_STATION"
trackingNumber: "A123456002"
}
Upvotes: 0
Views: 129