`
export function getPropByPath(obj, path, strict) {
let tempObj = obj;
path = path.replace(/[(\w+)]/g, '.$1');
path = path.replace(/^./, '');
let keyArr = path.split('.');
let i = 0;
for (let len = keyArr.length; i < len - 1; ++i) {
if (!tempObj && !strict) break;
let key = keyArr[i];
if (key in tempObj) {
tempObj = tempObj[key];
} else {
if (strict) {
throw new Error('please transfer a valid prop path to form item!');
}
break;
}
}
return {
o: tempObj,
k: keyArr[i],
v: tempObj ? tempObj[keyArr[i]] : null
};
};
`
key in tempObj 这里是不是要先判断下tempObj是不是对象。如果不是抛出和下面一样的异常?
1条答案
按热度按时间dffbzjpn1#
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.