javascript - Accessing the query variable from within callback -


take following example:

getoptions() {    let options = {};    if (this.props.location.hasownproperty('query')) {      const query = this.props.location.query;      const queriesmap = {       'createdby': 'createdby',       'state': 'state',       'created_from': 'created_at[from]',       'created_to': 'created_at[to]'     };      object.keys(query).map(function(key) {        if(queriesmap.hasownproperty(key)) {         options = object.assign(options, { queriesmap[key]: query[key] });       }     });   }    return options; } 

i'm using queriesmap object map url parameters build new url call api. problem query undefined when i'm trying access within .map callback.

how access query variable?

looks missing [] around queriesmap[key]. should options = object.assign(options, { [queriesmap[key]]: query[key] });.

also, options[queriesmap[key]] = query[key] rather object.assign


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

python - Error: Unresolved reference 'selenium' What is the reason? -

asp.net ajax - Jquery scroll to element just goes to top of page -