事实:
'alignment__'
,'font__'
,'leading__'
,'size__'
或'tracking__'
。我需要什么:
className
而不名称空间。false
。示例:
以下是我将要使用的数组集合的一个小例子:
p1 = ["alignment__left", "size__18px", "leading__170", "tracking__0", "font__Operator--1408"];
p2 = ["size__18px", "tracking__0", "font__Operator--1408", "alignment__left"];
p3 = ["alignment__left", "size__18px", "leading__170", "tracking__0", "font__Operator--1408"];
p4 = ["alignment__left", "size__18px"];
这个数组集合应该返回如下内容:
return {
alignment: 'left',
font: false,
leading: false,
size: '18px',
tracking: false
}
连连呢?我接近这个角度的每个角度看起来都很慢而且效率低下。我正在这个项目中使用lodash,以免简化任何事情。
答案 0 :(得分:1)
在下面找到使用lodash实现这一目标的简单方法:
const u = require('lodash');
var p1 = ["alignment__left", "size__18px", "leading__170", "tracking__0", "font__Operator--1408"];
var p2 = ["size__18px", "tracking__0", "font__Operator--1408", "alignment__left"];
var p3 = ["alignment__left", "size__18px", "leading__170", "tracking__0", "font__Operator--1408"];
var p4 = ["alignment__left", "size__18px"];
// I will obtain the unique values from the arrays given using the `union` method:
var union = u.union(p1, p2, p3, p4)
// Then, I will create an array of unique values that are included in all given arrays.
var inter = u.intersection(p1, p2, p3, p4)
// Finally, you can use the `difference` method to obtain those unique values
// that are not included in the `union` array.
var diff = u.difference(union, inter);
因此,在inter
数组中,您将拥有在上面定义的所有数组(p1,p2,p3,p4)中具有相同值的classNames,并且diff
数组将具有所有没有包含在每个数组中的命名空间。
答案 1 :(得分:1)
这是我扔在一起的东西。
'use strict';
const originalArrays = [
["alignment__left", "size__18px", "leading__170", "tracking__0", "font__Operator--1408"],
["size__18px", "tracking__0", "font__Operator--1408", "alignment__left"],
["alignment__left", "size__18px", "leading__170", "tracking__0", "font__Operator--1408"],
["alignment__left", "size__18px"]
]
const countInArray = (array, what) => {
lt count = 0;
for(let i = 0; i < array.length; i++) {
if(array[i] === what) {
count++;
}
}
return count;
};
const theFunction = (originalArrays) => {
const flattenedArray = originalArrays.reduce((a, b) => a.concat(b));
let interimResults = [];
let results = {};
for(let item of flattenedArray) {
if(countInArray(flattenedArray, item) === originalArrays.length) {
if(interimResults.indexOf(item) === -1) {
interimResults.push(item)
}
} else {
results[item.split('__')[0]] = false;
}
}
for(let result of interimResults) {
let parts = result.split('__');
results[parts[0]] = parts[1];
}
return results;
};
答案 2 :(得分:0)
我还没有测试过这个。如果我正确理解您的问题,以下可能是解决此问题的方法之一。我不能说这是否是最佳的。我会尝试找出更好的方法。但是现在这里是代码。
{{controller}}
答案 3 :(得分:0)
这是我想出的。没有像我预期的那样干净,但它似乎完成了工作。
GET blablabla/_search
{
"query": {
"bool": {
"must": [
{"match" : {"source" : "balblabla"}},
{"match" :{"blablablab" : "JBR"}},
{"match": {"city" : "blab bla"}},
{"match" : {"something": ["Balcony" , "Gym"]}}
]
}
}
}
&#13;
{
"error": {
"root_cause": [
{
"type": "query_parsing_exception",
"reason": "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?",
"index": "index name goes here",
"line": 8,
"col": 35
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "index name goes here",
"node": "4Qjq5UGPSZO2Qtg-ECI_mQ",
"reason": {
"type": "query_parsing_exception",
"reason": "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?",
"index": "index name goes here",
"line": 8,
"col": 35
}
}
]
},
"status": 400
}
&#13;