user95227 user95227 - 1 year ago 91
Javascript Question

How to write a taffyDB query using a variable as an attribute title?

I'm using taffyDB to query my javascript objects. I have a database

, where each item in the db has an attribute
Test Field
and an attribute

If I want to query all the items in
for which the value of
is "test", the following works:

var dbQuery = db({ Test_Field:"test" }).get()

However, if I want to query all the items in
for which the value of
Test Field
is "test", I cannot find any query that works. The following are my best attempts.

var dbQuery = db({ Test Field:"test" }).get()

var fieldName = "Test Field"
var dbQuery = db({ fieldName:"test" }).get()

var field = {}
field[name] = "Test Field"
var dbQuery = db({ field[name]:"test" }).get()

I want to grab the items where
Test Field
Any ideas how to query with a variable name so that I can check an attribute with space in its name like
Test Field

Thank you very much for your time. Let me know if I am being unclear or if you need anything else from me.

Answer Source

Have you tried db().filter({"Test Field": "test"}); or var obj = {}; obj[fieldName] = "test"; db().filter(obj);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download