0👍
The products[0].funds[0].fundProcessDate
doesn’t handle the case when the first product
is empty. My example below does handle it.
computed: {
date() {
const found = this.products.find(product =>
product.funds.some(fund => fund.fundsProcessDate != null)
);
return (found && found.funds[0].fundsProcessDate) || "01-01-2019"; //default date if not found from all of them
}
}
0👍
You can use Computed-Setter for this scenario.
data: function(){
return {
date: ''
}
},
computed: {
products: {
// setter
set: function (newValue) {
let products = newValue;
var year = this.selectedSchemeYear;
products.forEach(function(product){
product.funds.forEach(function(fund){
this.date = fund.fundsProcessDate;
})
});
}
}
},
<template>
<div>
<p>date: <b>{{date}}</b></p>
</template>
Source:stackexchange.com