Hej,
w rodzicu robię coś takiego
onMounted(() => {
getTransactions(paramsCurrentPeriod, erpTransactions); // tablica obiektów
getTransactions(paramsPreviousPeriod, erpTransactionsPrevious); // tablica obiektów
});
class="col-md-12"
v-for="item in erpTransactions"
:key="item.salesRepresentativeId"
>
<SaleRepresentativeStats
:data="item"
:previous-data="erpTransactionsPrevious"
/>
w pętli wyświetlam child przekazując do niego powyższe. Wewnątrz child potrzebuję wybrać jeden obiekt z previous-data gdzie item.id == previosu-data.id i z tym JAKBY sobie poradziłem tak
import { defineComponent, reactive, PropType } from "vue";
interface Option {
salesRepresentativeId: number;
salesRepresentativeName: string;
quantity: number;
net: number;
paymentLeft: number;
}
interface Options extends Array
<Option> {}
export default defineComponent({
name: "sale-representative-stats",
props: {
data: {
type: Object,
required: true,
},
previousData: {
type: Array as PropType<Options>,
required: true,
},
},
setup(props) {
const prevData: object[] = reactive([]);
const findPreviousDataById = () => {
const filtered = props.previousData.filter((obj) => {
return obj.salesRepresentativeId === props.data.salesRepresentativeId;
});
prevData.push(filtered);
console.log(prevData); // nie wiem dlaczego mam tutaj pusto
};
onMounted(() => {
findPreviousDataById();
});
return {
prevData,
};
},
});
to co robi funkcja findPreviousData() chce pokazać na widoku. Niestety ta tablica obiektów jest pusta.
nie wiem czy nie jest to spowodowane jakimś cyklem życia komponentu? Iteruję i pokazuję child i jeszcze coś w nim robię co ma zostać wyświetlone. Niby normalka ale nie wiem co robię źle, że ten array jest pusty w console.log ?