Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

联动数据配置问题 #163

Closed
newbiebie opened this issue Jul 28, 2020 · 10 comments
Closed

联动数据配置问题 #163

newbiebie opened this issue Jul 28, 2020 · 10 comments

Comments

@newbiebie
Copy link

多列联动数据源配置之后不显示,内存暴增, 只添加第一列数据正常显示,第二列数据添加进之后错误

@agiapp
Copy link
Owner

agiapp commented Jul 28, 2020

参考Demo进行使用,要注意数据源的格式

@newbiebie
Copy link
Author

看过demo, 联动的关系决定于parentKey, 只要把数据源填充到一个一维数组, 顺序应该没有什么关系吧, 本地json文件是数组嵌套数组的格式, 我把每一级的数据逐次添加,parentKey 也做对照了, 依然显示不出来。 填充模型的各属性值和demo中输出的也没差别。

@agiapp
Copy link
Owner

agiapp commented Jul 30, 2020

方便贴一下你调用的代码和部分数据源格式吗,我排查一下

@newbiebie
Copy link
Author

屏幕快照 2020-08-04 上午10 47 49

屏幕快照 2020-08-04 上午10 48 02

屏幕快照 2020-08-04 上午10 49 23

@newbiebie
Copy link
Author

中间第二张图片是demo中的方法, 我也截图出来了, 第三张是本地json 数据。

@agiapp
Copy link
Owner

agiapp commented Aug 4, 2020

找到原因了,数据源 key(GradeID) 不能出现和 parent_key(StageID) 相等的情况,不然在遍历数组的时候会出现死循环。
如:下面的数据源是可以的

{
  "Code": 1,
  "Message": "获取数据成功!",
  "GetStageInfoDto": [
      {
          "GetGradeInfoDto": [
              {
                  "GradeID": "11",
                  "Name": "一年级",
                  "StageID": "1"
              },
              {
                  "GradeID": "12",
                  "Name": "二年级",
                  "StageID": "1"
              },
              {
                  "GradeID": "13",
                  "Name": "三年级",
                  "StageID": "1"
              },
              {
                  "GradeID": "14",
                  "Name": "四年级",
                  "StageID": "1"
              },
              {
                  "GradeID": "15",
                  "Name": "五年级",
                  "StageID": "1"
              },
              {
                  "GradeID": "16",
                  "Name": "六年级",
                  "StageID": "1"
              }
          ],
          "Name": "小学",
          "StageID": "1"
      },
      {
          "GetGradeInfoDto": [
              {
                  "GradeID": "21",
                  "Name": "初一",
                  "StageID": "2"
              },
              {
                  "GradeID": "22",
                  "Name": "初二",
                  "StageID": "2"
              },
              {
                  "GradeID": "23",
                  "Name": "初三",
                  "StageID": "2"
              }
          ],
          "Name": "初中",
          "StageID": "2"
      },
      {
          "GetGradeInfoDto": [
              {
                  "GradeID": "31",
                  "Name": "高一",
                  "StageID": "3"
              },
              {
                  "GradeID": "32",
                  "Name": "高二",
                  "StageID": "3"
              },
              {
                  "GradeID": "33",
                  "Name": "高三",
                  "StageID": "3"
              }
          ],
          "Name": "高中",
          "StageID": "3"
      }
  ]
}

@newbiebie
Copy link
Author

可以了, 感谢! 但是发现一个新问题,stringPickerView.pickerMode = BRStringPickerComponentLinkage;多级联动的时候,设置stringPickerView.isAutoSelect = NO; 点击确定按钮回调无响应

@newbiebie
Copy link
Author

屏幕快照 2020-08-04 下午3 58 16

@agiapp
Copy link
Owner

agiapp commented Aug 4, 2020

多谢提醒,下个版本会更新

    @weakify(self)
    self.doneBlock = ^{
        @strongify(self)
        // 点击确定按钮后,执行block回调
        [self removePickerFromView:view];
        
        if (self.pickerMode == BRStringPickerComponentSingle) {
            if (self.resultModelBlock) {
                self.resultModelBlock([self getResultModel]);
            }
        } else if (self.pickerMode == BRStringPickerComponentMulti || self.pickerMode == BRStringPickerComponentLinkage) {
            if (self.resultModelArrayBlock) {
                self.resultModelArrayBlock([self getResultModelArr]);
            }
        }
    };

@agiapp
Copy link
Owner

agiapp commented Aug 6, 2020

已更新,联动选择器新增了如下属性:

/**
 *  最大层级数(列数) for `BRStringPickerComponentLinkage`, ignored otherwise.
 *  使用场景:默认可选,当数据源中有 key 等于 parentKey 情况时,必须要设置
 */
@property (nonatomic, assign) NSInteger numberOfComponents;

可以有效解决数据源中有 key 等于 parentKey 情况时,出现的死循环问题。

  • 上面的二级联动选择器可以设置 stringPickerView.numberOfComponents = 2; 不用再考虑 key 和 parentKey 有相等的情况

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants