0

I have this

       <Checkbox 
         label="View"
         :initialState="data.something"
         @updateStatus="updateCheckbox" >
       </Checkbox>

data.something is a boolean. I want to change this boolean if the checkbox changes. The checkbox emits the new value (true/false). I know i can use a function to do that easily but i have a lot of checkboxes, so how do i know which data.something i have to update? Is the only option to write a function for all the checkboxes or is there a better way?

2 Answers 2

1

I fixed it!

Somebody did give an answer but it wasn't entirely what I needed. But his answer was the missing piece!

@updateStatus="data.something = !data.something "

The problem was, I was too focused on getting the emitted value instead of listening to the event and then doing something!

Sign up to request clarification or add additional context in comments.

1 Comment

great to hear, Arvoci! I had to removed it, to think about it a little bit more...
0

Using the methods for this kind of work is the best way, and you don't need to care about which data.something you have to update. Because when you pass any object to the function, it references those params in your function. So when you modify that data inside the function, it will update your particular data.something.

Try to create a function and pass the object inside it, it will only update that "data".

Here is an example:

In event listen:

@updateStatus="inverseSomething(data)"

Method to update:

inverseSomething(data) {
        data.something = !data.something
      }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.