wuba / Fair

A Flutter package used to update widget tree dynamically. Fair提供一整套Flutter动态化解决方案
https://fair.58.com
BSD 3-Clause "New" or "Revised" License
2.64k stars 314 forks source link

convertObjectLiteralToSetOrMap为什么只转一层? #302

Open yx-mike opened 1 year ago

yx-mike commented 1 year ago

问题

我的fairProps有好几层 'fairData': { 'fairProps': { "adsk": null, "spoor": null, "title": null, "banners": [ { "renderTitle": "", "renderDesc": "", "positionIndex": null, "color": null, } ], "initIndex": null, "aspectRatio": 4.0344827586206895, "page": "hotPage", "tabName": null, }, },

但是在读取的时候会把错误: __op_idx__ is not a function

我自己调试了一下,发现convertObjectLiteralToSetOrMap只转了fairProps最外层的数据,把Object转成Map;但是内层的对象还是Object,但是fair_core.js和fair_jsbase.js没有在Object的原型增加__op_idx__方法。

convertObjectLiteralToSetOrMap为什么只转一层,如果fairProps数据层级很多怎么办?

目前我是自己去fair库里面改的。

环境信息

flutter doctor --verbose
[✓] Flutter (Channel vd/main, 2.5.1042, on macOS 13.3.1 22E772610a darwin-x64, locale zh-Hans-CN)
    • Flutter version 2.5.1042 at /Users/hxd/Documents/flutter/flutter
    • Upstream repository ssh://git@gitlab.vdian.net:60022/flutter/flutter.git
    • Framework revision a8cad5e28c (7 months ago), 2022-10-27 11:59:08 +0800
    • Engine revision b3af521a05
    • Dart version 2.14.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn
dependencies:
  fair: 3.0.0
yx-mike commented 1 year ago

后来我想了下,还是不修改js的convertObjectLiteralToSetOrMap方法了。

使用 对象+属性 的方式读取fairProps内部层次的数据。

`

Banner banner = Banner();

try {

  Banner tmpBanner = fairProps['banners'][i];

  banner.renderImage = tmpBanner.renderImage;

  banner.redirectUrl = tmpBanner.redirectUrl;

  banner.isExposured = false;

} catch (e) {

  banner.renderImage = jsonBanner['renderImage'];

  banner.redirectUrl = jsonBanner['redirectUrl'];

  banner.isExposured = false;

}

`