1

I am looking for how to do a "Select All" checkbox with Vue.js and actually a I kind of found a solution here.

The problem is I am using Vueify and doing everything on my .vue file so some syntax is different then on the example and I can't fix it!

My problem is on this part of the FiddleJS

for (user in this.users) {
    this.userIds.push(this.users[user].id);
}

This for is not recognized on my code I don't know why! If I insert a console.log(user) inside the for it returns:

Uncaught ReferenceError: user is not defined

Somebody knows what is happening?

2
  • 1
    Is the Reference Error from the browser or from Vue? It is impossible to get an Uncaught ReferenceError: user is not defined in JS as console.log(myUndefinedVariable) is valid. Check what the real generated JS is. I'd also add a for(var user in this.users). Commented Apr 1, 2016 at 16:54
  • Good question RainingChain! I don't know how to distingue it! The error is showing on the browser console so I guess it's from the browser right? Btw adding var solved my problem! Commented Apr 1, 2016 at 17:11

2 Answers 2

1

Guys it is simpler them I thought! As @RainingChain helped me on the comment above I jus need to add var to the for loop.

How I was doing

for (user in this.users) {
    this.userIds.push(this.users[user].id);
}

The right way to do

for (var user in this.users) {
    this.userIds.push(this.users[user].id);
}

Thanks!

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

Comments

0

Strangely. Your fix in your fiddle does not work for me. But works my fix in your html:

Your code:

<td><input type="checkbox" v-model="userIds" value="{{ user.id }}"></td>

My code:

<td><input type="checkbox" v-model="userIds" :value="user.id"></td>

Even without var in loop.

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.