- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个用于过滤对象的多复选框,我无法处理根据从复选框中选择的多个选项的单个条件返回必要对象的条件
我已经使用 && 运算符编写了条件,它会查找与指定条件完全匹配的内容
let json = [{
"id": 1,
"kba": false,
"email": true
},
{
"id": 2,
"kba": true,
"email": true
},{
"id": 3,
"kba": true,
"email": false
}]
function integrationFilter(selectedValue){
return truthy = json.filter(j => {
return j.kba === selectedValue.kba && j.email === selectedValue.email
})
}
let selectedValue1 = {"email": false}
let t2 = {"kba": true}
let t3 = {"email": true, "kba": false}
let op = integrationFilter(t2)
console.log(op)
根据我的上述逻辑,我得到了一个空数组。但我想得到结果,因为我将 kba 传递为 true。它们在对象中的键代表我拥有的多种选择,并且它可能会增长。
[ { id: 2, kba: true, email: true },
{ id: 3, kba: true, email: false } ]
最佳答案
您正在检查 &&
,它期望两个语句都为 true
。我修改了你的过滤器函数来处理你的场景。
let json = [{
"id": 1,
"kba": false,
"email": true
},
{
"id": 2,
"kba": true,
"email": true
}, {
"id": 3,
"kba": true,
"email": false
}
]
function integrationFilter(selectedValue) {
return json.filter(j => {
return Object.entries(selectedValue).every(([key, value]) => {
return j[key] === value;
});
});
}
let t1 = {
"email": false
}
let t2 = {
"kba": true
}
let t3 = {
"email": true,
"kba": false
}
console.log('t1:', integrationFilter(t1));
console.log('t2:', integrationFilter(t2));
console.log('t3:', integrationFilter(t3));
关于javascript - 通过对象过滤 MultiCheckbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55580469/
我有一个用于过滤对象的多复选框,我无法处理根据从复选框中选择的多个选项的单个条件返回必要对象的条件 我已经使用 && 运算符编写了条件,它会查找与指定条件完全匹配的内容 let json = [{
我有一个这样的多复选框元素: $element = new Zend_Form_Element_MultiCheckbox('infos', array('disableLoadDefaultDeco
我有一个 Angular 形式的多选字段,具有以下选项: vm.fields = [ { key: 'fruits', type: 'multiCheckbox', c
我有一个 Zend_Form_Element_Multicheckbox 并且我想将它的一些元素置于只读状态,我该怎么做? $colId = new Zend_Form_Element_Mul
我有这个表格: $this->addElement ( 'multiCheckbox', 'servers2', array (
我在获取 ajax 数据中的复选框值时遇到问题,它显示 undefined variable 。我使用下面的复选框,我在警报中获得值,但它没有在 ajax 中传递 这是我的代码 $na= jQu
我对这个 Zend 表单元素有疑问,如何读取 Multicheckbox 的元素状态? $type= new Zend_Form_Element_MultiCheckbox('typer');
我正在创建一个多选框,然后用一个循环填充它。是否可以在填充之后或填充期间禁用其中一个复选框? $multiOptions = array(); $multiCheckbox = new Zend_Fo
我正在尝试在 azure ad b2c 自定义策略声明架构中实现具有动态值的多复选框。 网址:https://learn.microsoft.com/en-us/azure/active-direct
我需要以只读模式显示表单,我正在使用 angular-formly 创建基于 Json 的表单。查看链接 http://angular-formly.com/#/example/other/read-
我正在使用 Xml 配置创建 Zend_Form,它定义了两个元素选择和多选框。我找到了这个 link它回答了我的一个问题,但是我找不到任何多复选框元素语法的示例。 感谢任何帮助。 这是我到目前为止所
我一直在谷歌搜索无济于事。我的一个表单中有一个多复选框表单元素。这是我用来创建它的代码: $this->add(array ( 'name' => 'thingyId', 'type'
我写这个问题是因为我在为 Zend Framework 1.9.3 的 _MultiCheckbox 元素设置默认值时遇到困难。 我使用多个选项创建 Zend_Form_Element_MultiCh
我是一名优秀的程序员,十分优秀!