test(){ let form={ bar_rule_txt:'{spu}-{master_attr_value}-{slave_attr_alias}', bar_rule_result:'', spu:'JPK1575G', master_attr_value:'黑色', master_attr_alias:'C001', slave_attr_value:'XXL', slave_attr_alias:'S002', }; let bar_rule_txt = form.bar_rule_txt; const regex = /\{([^}]+)\}/g; // 匹配大括号里面内容 let match,rule_attr=[]; while ((match = regex.exec(bar_rule_txt))) { //console.log(match[1]); // 输出捕获组内匹配的内容,即大括号内的内容 rule_attr.push(match[1]); } console.log(rule_attr);//打印正则表达式-匹配的内容 let propertyName = "form."+rule_attr[0]; console.log(propertyName);//form.spu let objname = eval(propertyName); console.log(objname);//JPK1575G },
转: https://www.cnblogs.com/mxjx/p/3259455.html
标签:bar,attr,对象,变量值,javascript,rule,let,txt,log From: https://www.cnblogs.com/fps2tao/p/18194404