How to evaluate with user made condition in typescript -


i have question regarding evaluating user made condition in typescript. in case: have ui , code behind (my model). example data object looks like:

let data = [     {         id: 0,         type: vw         eos,         costs: 23000     },     {         id: 1,         type: ford         van,         costs: 14000     },     {         id: 2,         type: nissan         sumara,         costs: 15000     },     {         id: 3,         type: honda         civic,         costs: 17500     } ] 

well, in ui user got input text field should make request give im cars red, example. user input this: "costs <=15000", string should used condition, result following ids: 1,2.

anyone idea how can use requeststring user in condition, like?:

data.foreach(object => {    if(usercondition) //an idea how solve this?    {       this.result.push(object);    }}); 

thanks suggestions!

the basic code looks this. word of caution: use filters rather taking inputs user can't possibly restrict user can enter in textbox. not sure how achieve complex conditions.

the usercondition hold condition let's cost < 15000. value set text input.

additem(usercondition: any) {   this.data.foreach(obj =>  {      var strcondition = 'obj.' + usercondition;      // console.log(strcondition) print obj.cost < 15000       if (eval(strcondition)) // evaluate expression , check condition      {        this.result.push(object);      }   });  } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -