| | |
| | | return true; |
| | | } |
| | | |
| | | static getObjDataByPath(obj, path) { |
| | | const arr = path.split('.'); |
| | | const reg2 = /\[(.*)]/g; |
| | | const reg4 = /\w+(?=\[)|(?<=\[)(.*?)(?=])/g; |
| | | let stack = []; |
| | | let temp; |
| | | arr.forEach(item => { |
| | | if (reg2.test(item)) { |
| | | while ((temp = reg4.exec(item))) { |
| | | stack.push(temp[0]); |
| | | } |
| | | } else { |
| | | stack.push(item); |
| | | } |
| | | }); |
| | | stack = stack.map(item => { |
| | | return item.replace(/^['"`]|['"`]$/g, ''); |
| | | }); |
| | | try { |
| | | return stack.reduce((pre, next) => { |
| | | return pre[next]; |
| | | }, obj); |
| | | } catch (err) { |
| | | return undefined; |
| | | } |
| | | } |
| | | // static getObjDataByPath(obj, path) { |
| | | // const arr = path.split('.'); |
| | | // const reg2 = /\[(.*)]/g; |
| | | // const reg4 = /\w+(?=\[)|(?<=\[)(.*?)(?=])/g; |
| | | // let stack = []; |
| | | // let temp; |
| | | // arr.forEach(item => { |
| | | // if (reg2.test(item)) { |
| | | // while ((temp = reg4.exec(item))) { |
| | | // stack.push(temp[0]); |
| | | // } |
| | | // } else { |
| | | // stack.push(item); |
| | | // } |
| | | // }); |
| | | // stack = stack.map(item => { |
| | | // return item.replace(/^['"`]|['"`]$/g, ''); |
| | | // }); |
| | | // try { |
| | | // return stack.reduce((pre, next) => { |
| | | // return pre[next]; |
| | | // }, obj); |
| | | // } catch (err) { |
| | | // return undefined; |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * 统计字符串占位宽度 |