声明数组searchFields工作灯JSONStore [英] Declare array into searchFields Worklight JSONStore

查看:191
本文介绍了声明数组searchFields工作灯JSONStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON对象到我的收藏与JSONStore是这样的:

I have a JSON object to my collection with JSONStore like this:

{
    name : 'name1',
    industry : ['Banking', 'Energy', 'Insurance', 'Media', 'Retail', 'Telco', 'Travel'],
    buyer : ['CMO'],
    link : 'foo.com' 
}

但是,如何可能声明行业领域进入searchFields?为了在数组中搜索模式。

But, how is possible declare the industry field into searchFields?, in order to search a pattern in the array.

干杯

推荐答案

有没有阵列键入搜索字段。你只能在对象的索引值是字符串布尔数量整数

There's no array type for search fields. You can only index values in objects that are string, boolean, number and integer.

您可以更改:

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

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

,然后使用以下搜索字段: {'industry.name':'串'} 。这将使你能够做类似 WL.JSONStore.get('收集')找到({'industry.name':'银行'},{确切:真})并取回像这样的一个对象:

and then use the following search field: {'industry.name' : 'string'}. That will enable you to do something like WL.JSONStore.get('collection').find({'industry.name' : 'Banking'}, {exact: true}) and get back an object like this one:

[{_id: ..., json: {name: ..., industry: [..., {name: Banking}, ...], buyer: ..., link: ...}}]

这是在文档中的一般术语的搜索领域部分<一个记录href=\"http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/devref/c_jsonstore_terminology.html\">here.

This is documented under the search field section of general terminology in the documentation here.

这将意味着写code这样的改变被添加到集合中的数据:

That would mean writing code like this to change the data being added to the collection:

var output = [];
['Banking', 'Energy', 'Insurance', 'Media'].forEach(function (element) {
    output.push({name: element});
});
console.log( JSON.stringify(output, null, ' ') ); 

另外,你也可以把它变成一个字符串:

Alternatively, you could also change it into a string:

{industry : ['Banking', 'Energy', 'Insurance', 'Media'].toString() }

和取回是这样的:

{industry : "Banking,Energy,Insurance,Media"}

然后就可以使用搜索栏 {行业:'字符串'} 并做类似 WL.JSONStore.get('收集') .find({产业:'能源'},{确切:假})来获得在<$ C $有物体能源某处C>行业字符串值。

Then you can use the search field {industry : 'string'} and do something like WL.JSONStore.get('collection').find({industry: 'Energy'}, {exact: false}) to get objects that have Energy somewhere in the industry value string.

仅供参考 - 功能要求<一个href=\"https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014907906&ps=25\">here.

FYI - Feature requests here.

这篇关于声明数组searchFields工作灯JSONStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆