这是个什么问题啊,都找不到问题在哪?有点懵啊。
- 当前 Bug 的表现(可附上截图)
这是自己自定义的组件
Component({ behaviors: [ 'wx://form-field' ], /** * 自定义类样式 */ externalClasses: [ 'box-class' , 'item-class' , 'select-class' ], /** * 组件的属性列表 */ properties: { items: { type: Array, value: [], observer: '_setCheck' }, selected: { type: String, value: '' , observer: '_setCheck' } }, /** * 组件的初始数据 */ data: { list: [] }, lifetimes: { attached: function () { this ._setCheck(); } }, /** * 组件的方法列表 */ methods: { bindCheckChange: function (e) { this .triggerEvent( 'selectevent' , e.detail.value); }, _setCheck: function () { const { items, selected } = this .data; const list = items.map(item => { return Object.assign({}, item, { check: selected == item.key }); }); console.log(list); this .setData({ list: list }); } } }) |
使用这个组件时时正确的,但是只要在重新setData 对应传入的items值,就会出现下边错误,找不到问题啊,也看不出来问题在哪,这错误信息也是懵逼的。
webviewScriptError Cannot read property 'item' of undefined;[Exparser] [Error] [Component] Event Listener Error @ wx-radio-group #(anonymous) TypeError: Cannot read property 'item' of undefined at n._handleItemRemoved (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:287555) at n.<anonymous> (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:167466) at i.safeCallback (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:129845) at i.call (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:129738) at n (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:132274) at http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:132856 at p (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:131821) at Function.l.dispatchEvent (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:132753) at Function.l.triggerEvent (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:132956) at n.b.triggerEvent (http: //127.0.0.1:53654/__pageframe__/__dev__/WAWebview.js:1:153041) (anonymous) @ VM2627:5 VM2629:4 |
我也没有用到啥item的属性啊,这啥玩意啊!
### 出现问题的原因,由于组件重新赋值的items为无序的话,会有上边的错误,然后真心不知道这个渲染错误的理由及原因。代码片段里有只要点击置换按钮,重新给组件的items赋值为无序数组,主要是看下默认的items跟置换后的items就知道啦,置换的items为无序的,默认的为有序的,必现问题。
# 然而最主要的是这错误跟错误提示差的十万八千里啊。
有序数据
areas: [{ id: 1, key: 1, value: '北京' }, { id: 2, key: 2, value: '上海' }, { id: 3, key: 3, value: '重庆' }, { id: 4, key: 4, value: '武汉' }, { id: 5, key: 5, value: '南京' }, { id: 6, key: 6, value: '深圳' }] |
无序数据
areas: [ { id: 3, key: 3, value: '北京' }, { id: 2, key: 2, value: '上海' }, { id: 4, key: 4, value: '重庆' }, { id: 6, key: 6, value: '武汉' }, { id: 1, key: 1, value: '南京' }, { id: 5, key: 5, value: '深圳' } ] |
2 回复