Vue.js 2 - How To Pass Data From Child Component To Parent - vuejs2

I have an app where users create a list of patients. Each patient (child component) contains a name and age. The app will calculate the number of patients and sum of all of the patient's age. How would I pass information from the child component to the parent component?
Note - In my <report> component I am currently hard coding the total-age attribute value to 0.
Currently, I have an addPatient() method addd to my Vue instance which pushes null into the patients array. I feel like I should be pushing something else other then null into this array. I have a v-for for each patients.
https://codepen.io/anon/pen/pOgdmW

Related

Laravel 8 passing variables from partial view to parent view

I am using laravel 8.74 and I am trying to pass data from a child's view to the parent view guest layout.
The child view is using tag to inherit the guest view.
This way I was assuming I can use the attributes bag and the #props([]) to get and set the variables to the parent view.
Child or partial view
<x-guest-layout :meta_description="$obj->DescriptionToString( 150 )">
While the attributes bag does work.
Guest view
<x-meta name="description" :content="$attributes->get('meta_description')"/>
When using the #props I can only access the variable if it has a default value otherwise, I get “undefined variable.
Guest view
#props(["meta_description" => "A description"])
It’s so far, the same behavior as a component and that is what I was expecting.
If the #props function exists, then the “meta_description” variable does not exist anymore in the attributes bag, which is normal. But again does not exist if I do not define a default value and the value passed from the child view is overwritten.
Is there something I forgot or misunderstood?
Dough!!
One of my Beaker moments...
Just realized that the guest and app layouts have class component.
App/View/Components

Aurelia dynamically bound variable with template string

I am trying to set the dynamic id of a component within a component.
So the child component has a bindable uniqueId property.
The parent component has its own uniqueId which I am trying to keep into the child component's uniqueId, as such sort of following BEM convention:
<text-input-editor repeat.for="boxSide of boxSides"
uniqueId.bind="box-editor-${uniqueId}__${boxSide}-input"></text-input-editor>
But this gives me the following error: unconsumed token { (abridged).
I tried with using the <let></let> element as in https://aurelia.io/docs/templating/custom-elements#declarative-computed-values but that didn't work either.
I am not sure how to do this in the view, as I would rather not handle this at the controller's level (this is just one of many components in that view).
Assuming uniqueId has a value in your viewmodel, as the expression already has a ".bind" format, this would be:
<text-input-editor repeat.for="boxSide of boxSides"
uniqueId.bind="'box-editor-' + uniqueId + '__' + boxSide + '-input'"></text-input-editor>
Otherwise, it could be:
<text-input-editor repeat.for="boxSide of boxSides"
uniqueId="box-editor-${uniqueId}__${boxSide}-input"></text-input-editor>
A working version can be reviewed at:
CodeSandbox
So I didn't try specifically Cristián Ormazábal's answer but I fixed my problem by changing uniqueId to unique-id:
<text-input-editor repeat.for="boxSide of boxSides"
unique-id="box-editor-${uniqueId}__${boxSide}-input""
></text-input-editor>

Vuejs update a list in reactive manner

I've two components
1. viewAndUpdateDish.vue
2. updateDish.vue
In viewAndUpdateDish,
user pick a restaurant from the drop down
dishes of that particular restaurant will filter out and loaded to the table.
then the user hit the update button on a dish and go to updateDish.vue component and update the dish.
then after he update the dish user is redirected to the viewAndUpdateDish
When the user redirected to the viewAndUpdateDish that previously selected restaurant should be selected and dishes should loaded. This is my use case.
What I did so far is,
create a variable called pickedRestaurantId in vuex store and when user select a restaurant I updated that Id.
And in the updateDish component at the end of the update function, I emit a event like this, this.$root.$emit("clickedUpdate");
And then in the viewAndUpdateDish compoent I did
mounted() {
this.$root.$on("clickedSomething", () => {
this.loadDishes(this.pickedResViewAndUpdateDish);
});
},
But this doesn't seems work!
How do I achieve this using vuejs?
Hope my question is clear to you.
On your "viewAndUpdateDish" component after your update logic you can do the following:
this.$emit('clickedUpdate',yourResturantId);
then on your parent component make sure you are listening to the "clickedUpdate" event:
<update-dish #clickedUpdate="loadDishes($event)"></update-dish> .

MVC Complex ViewModel

I need to build a sample MVC UI app using Kendo UI.
I have 2 multiselect widgets for airline names and airport names respectively and below I have a grid with airline airport data.
Now when I select airlines or airports in the multiselect, upon clicking a Fetch button, the grid should refresh.
I created a ViewModel named AirlineAirportViewModel for containing List<Airlines>, List<Airports> and List<AirlineAirports>.
I instantiate the List<AirlineAirports> in the Get action method of the controller and fill the other two lists getting distinct airline and airport values from the List<AirlineAirports>.
While posting on filter button click, I am able to get action parameters as 2 List<string> types which contain only the selected multiselect items
Instead of that, I want this action parameter of type AirlineAirportViewModel so that in future, I will be able to add more filter widgets and the number of parameters stay one only.
Now, am I approaching this in the right way ? If I need the ViewModel as action parameter, where should I store the selected items from the multiselects ?

how to get the tag property (Value) of the Grand Parent Node

I am new to the site and for VB.net as well.
I want to get the Tag value of the Grand Parent Node in a treeview control while clicking on the Grand child. I have a Tree populated from database table and for each node i set the Tag property binded to an integer number. this tree has Three Levels.
-Grand Father
--Father
---Child
-Grand Father
--Father
---Child
.
.
. and so on...
What I exactly need is , when i click on the child node then i want to store the tag value of the Grand Father of this child n a variable...
I hope you understands what i needed.
Any help will be highly Appreciated.