Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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
Arrays 将数组声明到searchFields Worklight JSONStore中_Arrays_Search_Field_Ibm Mobilefirst_Jsonstore - Fatal编程技术网

Arrays 将数组声明到searchFields Worklight JSONStore中

Arrays 将数组声明到searchFields Worklight JSONStore中,arrays,search,field,ibm-mobilefirst,jsonstore,Arrays,Search,Field,Ibm Mobilefirst,Jsonstore,我使用JSONStore在我的集合中有一个JSON对象,如下所示: { name : 'name1', industry : ['Banking', 'Energy', 'Insurance', 'Media', 'Retail', 'Telco', 'Travel'], buyer : ['CMO'], link : 'foo.com' } 但是,如何将行业字段声明为searchFields?以便在数组中搜索模式 干杯搜索字段没有数组类型。您只能索引对象中的

我使用JSONStore在我的集合中有一个JSON对象,如下所示:

{
    name : 'name1',
    industry : ['Banking', 'Energy', 'Insurance', 'Media', 'Retail', 'Telco', 'Travel'],
    buyer : ['CMO'],
    link : 'foo.com' 
}
但是,如何将行业字段声明为searchFields?以便在数组中搜索模式


干杯

搜索字段没有
数组
类型。您只能索引对象中的值,这些对象是
字符串
布尔值
数字
整数

你可以改变:

{ industry : ['Banking', 'Energy'] }
致:

然后使用以下搜索字段:
{'industry.name':'string'}
。这将使您能够执行类似于
WL.JSONStore.get('collection').find({'industry.name':'Banking'},{exact:true})
的操作,并返回如下对象:

[{_id: ..., json: {name: ..., industry: [..., {name: Banking}, ...], buyer: ..., link: ...}}]
这将记录在文档中“通用术语”的“搜索”字段部分中

这意味着要编写这样的代码来更改添加到集合中的数据:

var output = [];
['Banking', 'Energy', 'Insurance', 'Media'].forEach(function (element) {
    output.push({name: element});
});
console.log( JSON.stringify(output, null, ' ') ); 
或者,您也可以将其更改为字符串:

{industry : ['Banking', 'Energy', 'Insurance', 'Media'].toString() }
然后得到像这样的东西:

{industry : "Banking,Energy,Insurance,Media"}
然后,您可以使用搜索字段
{industry:'string'}
执行类似
WL.JSONStore.get('collection')。查找({industry:'Energy'},{exact:false})
以获取
industry
值字符串中某处具有
能量的对象


仅供参考-功能请求。

搜索字段没有
数组类型。您只能索引对象中的值,这些对象是
字符串
布尔值
数字
整数

你可以改变:

{ industry : ['Banking', 'Energy'] }
致:

然后使用以下搜索字段:
{'industry.name':'string'}
。这将使您能够执行类似于
WL.JSONStore.get('collection').find({'industry.name':'Banking'},{exact:true})
的操作,并返回如下对象:

[{_id: ..., json: {name: ..., industry: [..., {name: Banking}, ...], buyer: ..., link: ...}}]
这将记录在文档中“通用术语”的“搜索”字段部分中

这意味着要编写这样的代码来更改添加到集合中的数据:

var output = [];
['Banking', 'Energy', 'Insurance', 'Media'].forEach(function (element) {
    output.push({name: element});
});
console.log( JSON.stringify(output, null, ' ') ); 
或者,您也可以将其更改为字符串:

{industry : ['Banking', 'Energy', 'Insurance', 'Media'].toString() }
然后得到像这样的东西:

{industry : "Banking,Energy,Insurance,Media"}
然后,您可以使用搜索字段
{industry:'string'}
执行类似
WL.JSONStore.get('collection')。查找({industry:'Energy'},{exact:false})
以获取
industry
值字符串中某处具有
能量的对象

供参考-功能请求