admin管理员组文章数量:1402958
im using this code
var db = new Dexie("likeTest");
db.version(1).stores({
friends: "name,age"
});
db.on('populate', function() {
db.friends.add({name: "Foo Barsson", age: 33});
});
db.open();
db.friends.filter (function (friend) { return /Bar/.test(friend.name); })
.toArray()
.then(function(result) {
alert ("Found " + result.length + " friends containing the word 'Bar' in its name...");
});
I wanted to know how I can use a variable instead of the search?
Ex.
var VarTest = 'Dani';
db.friends.filter (function (friend) { return /VarTest/.test(friend.name); })
im using this code
var db = new Dexie("likeTest");
db.version(1).stores({
friends: "name,age"
});
db.on('populate', function() {
db.friends.add({name: "Foo Barsson", age: 33});
});
db.open();
db.friends.filter (function (friend) { return /Bar/.test(friend.name); })
.toArray()
.then(function(result) {
alert ("Found " + result.length + " friends containing the word 'Bar' in its name...");
});
I wanted to know how I can use a variable instead of the search?
Ex.
var VarTest = 'Dani';
db.friends.filter (function (friend) { return /VarTest/.test(friend.name); })
Share
Improve this question
asked Mar 26 at 22:38
Dani CarlaDani Carla
938 bronze badges
1
- do mean can you bind the regex to a variable? yes?.. VarTest.test(friend.name) – danielRICADO Commented Mar 26 at 22:49
1 Answer
Reset to default 3You need to use //
when assigning to VarTest
:
var VarTest = /Dani/;
db.friends.filter (function (friend) { return VarTest.test(friend.name); })
If you want to make the regular expression dynamically from a string, use the RegExp
constructor:
var VarTest = new RegExp('Dani');
本文标签: javascriptdexiejs using variable in LIKE operatorStack Overflow
版权声明:本文标题:javascript - dexie.js using variable in LIKE operator - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744122381a2591800.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论