admin管理员组文章数量:1391975
I'm trying to create a search function in javascript using parse where a field contains a string. I've already search through the documents of parse but I can't find something similar to what I want. I want to query something like this:
query.like("contents", "%string%"); // example only this code does not exist.
Can any one know what method in parse I need?
In iOS I find this method whereKey:containsString:
but I think containsString
is not available in javascript.
I'm trying to create a search function in javascript using parse. where a field contains a string. I've already search through the documents of parse. but I can't find something similar to what I want. I want to query something like this:
query.like("contents", "%string%"); // example only this code does not exist.
Can any one know what method in parse I need?
In iOS I find this method whereKey:containsString:
but I think containsString
is not available in javascript.
- Do you mean something like indexOf, but with wildcard? – Trojan Commented Jan 21, 2014 at 8:53
- no I'm referring to parse query. – khatzie Commented Jan 21, 2014 at 8:54
1 Answer
Reset to default 6There is a way to do this, but the documentation warns that it may timeout on larger data sets. The solution is to add a constraint the query using a regular expression. Use the query constraint matches(key, regex).
Assuming there is a class named "Post" and it has a string attribute named "contents", then:
var query = new Parse.Query(Post);
query.matches("contents", ".*string.*");
query.find()
To AND multiple conditions, add more query matches constraints:
var query = new Parse.Query(Post);
query.matches("contents", ".*string.*");
query.matches("otherAttribute", ".*otherString.*");
query.find()
Using the Parse. JavaScript SDK, it is possible to use a logical OR:
var redQuery = new Parse.Query("Post");
redQuery.equalTo("color", "red");
var blueQuery= new Parse.Query("Post");
blueQuery.equalTo("color", "blue");
var mainQuery = Parse.Query.or(redQuery, blueQuery);
本文标签: Parsecom search with wild character using javascriptStack Overflow
版权声明:本文标题:Parse.com search with wild character using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744707398a2620923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论