Skip to content

Commit

Permalink
fix(wx-react): 修复dataPath 在数据为数组的情况下,结构为a.[b].c的bug,修改为a[b].c
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Aug 7, 2019
1 parent f00420b commit ee8f61f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/wx-react/miniprogram_dist/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default function render(vnode, parentInst, parentContext, data, oldData,
// 当Ua的key由Ka --> Kb 的时候, 那么组件变为Ub负责来渲染这一块, 故而需要给予Ub对应的数据
// 对于明确且唯一的key, 小程序和React处理是一致的
const vIndex = data[datakey].length - 1
render(subVnode, parentInst, parentContext, subData, oldSubDataKeyMap[subKey], `${dataPath}.${datakey}.[${vIndex}]`)
render(subVnode, parentInst, parentContext, subData, oldSubDataKeyMap[subKey], `${dataPath}.${datakey}[${vIndex}]`)
}
} else {
let oldSubData = null
Expand Down
7 changes: 3 additions & 4 deletions packages/wx-react/miniprogram_dist/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ export function filterContext(nodeName, parentContext) {


export function setDeepData(inst, v, path) {
const arr = path.split('.')
const arr = path.split(/[.\[]/)

let tmpObj = inst
for (let i = 0; i < arr.length - 1; i++) {
const sk = arr[i]

if (sk.charAt(0) === '[' && sk.charAt(sk.length - 1) === ']') {
const index = Number(sk.substring(1, sk.length - 1))
if (sk.charAt(sk.length - 1) === ']') {
const index = Number(sk.substring(0, sk.length - 1))
if (!Number.isNaN(index)) {
tmpObj = tmpObj[index]
} else {
Expand Down

0 comments on commit ee8f61f

Please sign in to comment.