Small procedure implementing multiple column selectors

Example of this article shared a small program to implement the specific code of multi-column selector for your reference, the specific content is as follows

code divided into two parts, first wxml

    species  *       {Multiarray [0] [MultiIndex [0]]}} {{Multiarray [1] [MultiIndex [1]]}} {{Multiarray [2] [MultiInDex [2]]}}          Secondly JS    
PAGE ({/ ** * Page initial data * / data: {ObjectMultishow: [], ObjectMultiarray: [], multiarray: [], multiIndex: [], checkein: []}, / ** * Lifecycle function – listening page Load * ObjectMultMultiSHow- – Match a multi-column selector rendering data Corresponding to JSON data (including ID, ParentID, Name) * Multiarray – Multi-column selector rendering data * / onload: function (options) {// Initialize Let Data = {ObjectMultiTishow: this .DATA.Objectmultishow, ObjectmultiArray: this.data.objectMultiArray, multiArray: this.data.multiArray, multiIndex: this.data.multiIndex, checkeIndex: this.data.checkeIndex} data.objectMultiArray =[[{id: 0, name: ‘No vertebrates’ }, {ID: 1, Name: ‘Spine Animals’}], [{ID: 0, Name: ‘Bili Animals’, Parentid: 0}, {ID: 1, Name: ‘Linear Animals’, ParentID: 0 }, {ID: 2, Name: ‘link animals’, Parentid: 0}, {ID: 3, Name: ‘Software Animals’, Parentid: 0}, {ID: 4, Name: ‘Arthropod’, ParentID: 0}, {ID: 5, Name: ‘Fish’, Parentid: 1}, {ID: 6, Name: ‘amphibian’, Parentid: 1}, {ID: 7, Name: ‘Reptile’, ParentID: 1}], [{ID: 0, Name: ‘Pork Aphid’, Parentid: 0}, {ID: 1, Name: ‘Suvusa’, Parentid: 0}, {ID: 2, Name: ‘蛔蛔’, Parentid: 1}, {ID: 3, Name: ‘Ant’, Parentid: 2}, {ID: 4, Name: ‘Antham, Parentid: 2}, {ID: 5, Name:’ River 蚌 ‘, ParentID : 3}, {iD: 6, Name: ‘Snail’, Parentid: 3}, {ID: 7, Name: ‘蛞蝓’, ParentID: 3}, {ID: 8, Name: ‘Insect’, ParentID: 4}, {ID: 9, Name: ‘Crock Animal’, Parentid: 4}, {ID: 10, Name: ‘Spider – shaped Animals’, Parentid: 4}, {ID: 11, Name: ‘Multi – Animals’, ParentID: 4}, {ID: 3, Name: ‘squid’, Parentid: 5}, {ID: 4, Name: ‘with fish’, Parentid: 5}, {ID: 3, Name: ‘Frog’, ParentID: 6}, {ID : 4, Name: ‘Doll Fish’, Parentid: 6}, {ID: 3, Name: ‘Lizard’, ParentID: 7}, {ID: 4, Name: ‘Turtle’, ParentID: 7}, {ID: 4 , Name: ‘Gecko’, Parentid: 7},]] Data.ObjectMultiTishow = data.objectmultiarray.map (item, index) => {if (index> 0) {iTEM = Item.filter (i => i. ParentID === Data.ObjectMultiarray [index – 1] [0] .id)} Return Item}) Data.Multiarray = data.objectMultiTishow.map (item => {item = item.map (i => i.Name) Return Item}) Console.log (data.multiIndex) // update data this.setData (data)}, bindMultiPickerChange: function (e) {console.log ( ‘picker change transmission selected, carrying a value’, e.detail.value) This.SetData ({Multiindex: E.Detail.Value})}}}, bindmultipickercolumnchange: Function (e) {console.log (‘Modified list “, e.detail.column,’, value ‘, E.DETAIL. Value); // Initialization data var data = {ObjectMultishow: this.data.Objectmultishow, multiarray: this.data.multiarray, multiindex: this.data.multiindex}; // After changing the number of data, the last few columns Select 0 options (reset) DATA.MULTIINDEX [E.Detail.column] = E.Detail.Value; for (let i = e.detail.column; i
item.parentId === data.objectmultishow [i ] [Data.MultiInDex [i]]]]. ID) Data.Multiarray [i + 1] = data.objectmultishow [i + 1] .map (item => item.name)} / * switch (e.detail.column) {cas 0: DATA. ObjectMultishow [1] = arry [1] .filter (item => item.parentID === Data.ObjectMultMultiTishow [0] [data.multiindex [0]]. id) data.Multiarray [1] = data.objectmultishow [1] .map (item => item.name) Data.objectMultishow [2] = arry [2] .filter (item => item.parentId === data.objectmultishow [1] [data.multiindex [1]]]] .id) Data.Multiarray [2] = data.objectmultishow [2] .map (item => item.name) Break; case 1: data.objectmultishow [2] = arry [2] .filter (item => iTem. ParentID === Data.objectMultishow [1] [Data.MultiIndex [1]]]]]. ID) Data.Multiarray [2] = data.objectmultishow [2] .map (item => item.name)} * / // Data Update this.SetData (DATA);}})

The official component -Picker selected by the WXML section is represented by the official document Mode = MultiSelector, indicating using multiple column selectors.
Other parameters, I spit under: First, the Range-bound two-dimensional data can only be a two-dimensional array of strings, such as[[“A”, “B”], [” C “,” D “]], such wordsThe selector is the first column A, B option, the second column C, D option. It feels beautiful. However, do you do this? The multi-column selectors we do are not just a page show. If you have docked data with the background, you will be in the case. What I need is an object with the ID, and the WXML page does not support the function method of writing MAP in bracket binding data. Therefore, the data from our posttail passed to transform, extract the NAME to bind data.
  The second is Value, which originally thought this is the first aiented in the corresponding item: A If corresponding C, B is corresponding to D. Selecting BD should be [1, 1], but in fact [1, 0]. That is, the first few corresponding to the corresponding page (BD, the first column on the page has two options, the second column is there and only one d) < data.multiIndex.length - 1; i++) {
   data.multiIndex[i + 1] = 0
  }
 
  /**
   * 改变第i列数据之后,后几列数据更新
   * 两种写法:for 和 switch,switch为三列选择器写法,for由switch精简拓展过来,可用于多列选择器
   * swich写法:如果更改的是第一列数据,第二列数据通过filter筛选(parentId = 第一列选中项id),同时更新第三列数据
   *      如果更改的是第二列数据,更新第三列数据 通过filter筛选(parentId = 第二列选中项id)
   */
  let arry = this.data.objectMultiArray
  for (let i = e.detail.column; i   Other methods about the bindchange binding are Click to confirm Button trigger, BindColumnChange binding method is to flig in the multi-column selector, so as to Bindcancel binding feeling is joke, the data changes in real time, canceling the need to bind a intermediate value to achieve the effect, here is not done here. 
I used five data

ObjectMultishow: [] Select the ID Object object array

ObjectMultiarray: [] Background ID, ParentID object Array

Multiarray: [] WeChat small program components required string 2D array

MultiIndex: [] Selected object array of WeChat small program components

CheckeIndex: [ ] Based on the middle value of Bindcancel (temporarily not done)
  • In order to achieve the true multi-column effect I think, I don’t have to sell the flesh, and the various humiliation agreements reached with the big brother of Taiwan. The first column array of data formats does not take ParentID because there is no Parent. Second column PARentID corresponds to the first column ID, the third column ParentID corresponds to the second column ID, if there are more, can be pushed in order. Then obtain the required additional data in turn according to the requirements, and complete the data initialization.
  • Then, when sliding the multi-column selector, dynamically update the data of the latter column, and the processing I did is the update one column data and select the first option by default.
  • Detailed note is written, and more is more configured, and the specific function code is very small.
  • Personally, the applet is not a write code, but is set up in the configuration option.
  • The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment