function getTemplate( pattern , data ){ let str = "" let stack = [] for( let key of pattern ){ if( key === "{" ){ stack.push( str ) str = "" }else if( key === "}" ){ const _data = stack.pop() const result = data[str] str = _data + result }else if( key === "$" ){ continue }else{ str += key } } return str } 算法还得继续加强,加油