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?
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!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.