Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js vue选中所有复选框,其中包含由计算方法生成的值_Vue.js - Fatal编程技术网

Vue.js vue选中所有复选框,其中包含由计算方法生成的值

Vue.js vue选中所有复选框,其中包含由计算方法生成的值,vue.js,Vue.js,我的页面顶部有一个“全选”复选框,单击它时,它应该选中所有复选框。这是我的密码: 学生 撤销选择全部 {{behavior.studentID.firstName} data(){ 返回{ 正片名称:“”, 行为主义者:[], checkedds:[], 选定:[] }; }, 计算:{ 选择全部:{ get:function(){ 返回this.behaviorList?this.selected.length==this.behaviorList.length:false; }, 设置:

我的页面顶部有一个“全选”复选框,单击它时,它应该选中所有复选框。这是我的密码:


学生
撤销
选择全部 {{behavior.studentID.firstName}
data(){
返回{
正片名称:“”,
行为主义者:[],
checkedds:[],
选定:[]
};
},
计算:{
选择全部:{
get:function(){
返回this.behaviorList?this.selected.length==this.behaviorList.length:false;
},
设置:函数(值){
var=[];
让自我=这个;
如果(值){
this.behaviorList.forEach(函数(行为){
var getDataType=behavior.dataType
var getID=行为。\u id
var getStudentID=行为.studentID.\u id
var getActionDate=behavior.actionDate
var getGeneratedID=self.setCheckedValue(getDataType、getID、getStudentID、getActionDate);
mySelected.push(getGeneratedID);
});
}
self.selected=mySelected;
console.log(“自选”)
console.log(自选择)
}
}
},    
方法:{
setCheckedValue(数据类型、id、studentID、actionDate){
返回“1:+dataType+”;2:+id+”;3:+studentID+”;4:+actionDate
},
撤销积分(){
var pointsToRevoke=this.checkedds;
console.log(“pointsToRevoke”)
console.log(pointsToRevoke)
}

当我点击
全选复选框时,控制台将显示self.selected将具有所有复选框的id。但问题是所有显示值的复选框都未选中…

很难提供帮助,因为您的代码尚未完成。但我的做法有点不同。我希望能帮助您

const list=[
{id:1,名称:'newyork',选中:true},
{id:2,名称:'Sydney',选中:false},
{id:3,名称:'London',选中:false},
{id:4,名称:'Chicago',选中:true}
]
新Vue({
el:“#应用程序”,
数据(){
返回{
列表
isAllChecked:错误
};
},
方法:{
checkAll:function(){
this.list=this.list.map(城市=>({…城市,
选中:!this.isAllChecked
}))
this.isAllChecked=!this.isAllChecked
}
},
计算:{
GetAllCheckEdds:函数(){
返回此.list.filter(city=>city.checked).map(city=>city.id)
},
getnotallcheckedds:function(){
返回此.list.filter(city=>!city.checked).map(city=>city.id)
}
}
});

  • {{city.name}
全部检查
已检查的ID:{getAllCheckedIDs} 未检查的ID:{{getNotAllCheckedIDs}
很难帮助您,因为您的代码尚未完成。但我会以不同的方式处理此问题。我希望可以帮助您

const list=[
{id:1,名称:'newyork',选中:true},
{id:2,名称:'Sydney',选中:false},
{id:3,名称:'London',选中:false},
{id:4,名称:'Chicago',选中:true}
]
新Vue({
el:“#应用程序”,
数据(){
返回{
列表
isAllChecked:错误
};
},
方法:{
checkAll:function(){
this.list=this.list.map(城市=>({…城市,
选中:!this.isAllChecked
}))
this.isAllChecked=!this.isAllChecked
}
},
计算:{
GetAllCheckEdds:函数(){
返回此.list.filter(city=>city.checked).map(city=>city.id)
},
getnotallcheckedds:function(){
返回此.list.filter(city=>!city.checked).map(city=>city.id)
}
}
});

  • {{city.name}
全部检查
已检查的ID:{getAllCheckedIDs} 未检查的ID:{{getNotAllCheckedIDs}
您在哪里更新您的
v-model=“checkedds”
当调用selectAll函数时?我想帮你,但你让它变得很困难,因为你的代码不完整,无法生成一个fork,但是你可以使用ref指令将复选框的元素父元素作为目标,并使用简单的vanilla js将所有复选框设置为选中。@skribe
checkedIDs
的值在下声明为数组<代码>数据
。如果我手动选中了任何复选框,然后按revoke按钮调用
revokePoints
,checkedIDs将包含每个选中复选框的值。我已经更新了一点代码。您在哪里更新您的
v-model=“checkedIDs”
当调用selectAll函数时?我想帮你,但你让它变得很困难,因为你的代码不完整,无法生成一个fork,但是你可以使用ref指令将复选框的元素父元素作为目标,并使用简单的vanilla js将所有复选框设置为选中。@skribe
checkedIDs
的值在下声明为数组<代码>数据。如果我手动选中了任何复选框,然后按revoke按钮调用
revokePoints
,CHECKEDID将包含每个选中复选框的值。我已稍微更新了代码。