react-WeUI及相關組件的運用

1.react-weui之picker組件的運用;

第一步,上官網文檔:

Picker Picker

Mobile select ui, currently only support Touch Events

Props

Name Type Defaults Details
actions array [] consists of array of object(max 2) with property label and others pass into element
defaultSelect array   default group index thats selected, if not provide, automatic chose the best fiting item when mounted
groups array [] array objects consists of groups for each scroll group
lang object   language object consists of leftBtn andrightBtn
onCancel func   excute when the popup about to close
onChange func   on selected change, pass property selected for array of slected index togroups
onGroupChange func   trigger when individual group change, pass property(item, item index in group, group index in groups, selected,picker instance)
show bool false display the component
從官網文檔中可以得知:語言(lang)是一個對象,它分爲左右兩個鍵,左鍵(leftBtn)和右鍵(rightBtn)進行設置,那麼接下來怎麼設置對象的屬性,在哪裏設置這是一個關鍵性的問題;

如果沒有涉及到子父級組件傳值的話,state設置,一般設置語言是不會涉及到子父級傳值問題;

所以接下來上代碼:

 this.state={
          
            picker_lang:{
            	leftBtn:'取消',
            	rightBtn:'確定'
            }
        }
設置react-weui中的默認值爲第一項通過defaultSelect
defaultSelect={Array(this.state.picker_group.length).fill(0)}

默認值的選項中,Array.fill(),表示數組的填充,接下來我將爲大家講解該數組是如何填充的,接下來,我將用代碼演示:

		var arr = [0,0,1,2,3];
		arr.fill(2);
		console.log(arr)//[2,2,2,2,2]
表示爲一個值時,fill中的參數會將數組所有的元素,全部填充爲2;

接下來也會爲大家演示爲兩個參數是怎樣填充的,請欣賞下面的代碼:

var arr = [0,0,1,2,3];
		arr.fill(2,2);
		console.log(arr)//[0,0,2,2,2]
表示數組從數組的第三位的開始填充第一個參數;

var arr = [0,0,1,2,3];
arr.fill(1,2,4);
console.log(arr)//[0,0,1,1,3]
fill(a,b,c)表示從b填充a的數值到c(不包括c);
這就是reactweui中picker組件運用的屬性值


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章