@@ -32,6 +32,7 @@ export default createComponent({
3232
3333 props : {
3434 valueKey : String ,
35+ allowHtml : Boolean ,
3536 className : String ,
3637 itemHeight : Number ,
3738 defaultIndex : Number ,
@@ -226,20 +227,48 @@ export default createComponent({
226227 this . transitionEndTrigger ( ) ;
227228 this . transitionEndTrigger = null ;
228229 }
230+ } ,
231+
232+ genOptions ( ) {
233+ const optionStyle = {
234+ height : `${ this . itemHeight } px`
235+ } ;
236+
237+ return this . options . map ( ( option , index ) => {
238+ const text = this . getOptionText ( option ) ;
239+ const data = {
240+ style : optionStyle ,
241+ class : [
242+ 'van-ellipsis' ,
243+ bem ( 'item' , {
244+ disabled : isOptionDisabled ( option ) ,
245+ selected : index === this . currentIndex
246+ } )
247+ ] ,
248+ on : {
249+ click : ( ) => {
250+ this . onClickItem ( index ) ;
251+ }
252+ }
253+ } ;
254+
255+ if ( this . allowHtml ) {
256+ data . domProps = {
257+ innerHTML : text
258+ } ;
259+ }
260+
261+ return < li { ...data } > { this . allowHtml ? '' : text } </ li > ;
262+ } ) ;
229263 }
230264 } ,
231265
232266 render ( ) {
233- const { itemHeight } = this ;
234267 const wrapperStyle = {
235268 transform : `translate3d(0, ${ this . offset + this . baseOffset } px, 0)` ,
236269 transitionDuration : `${ this . duration } ms` ,
237270 transitionProperty : this . duration ? 'all' : 'none' ,
238- lineHeight : `${ itemHeight } px`
239- } ;
240-
241- const optionStyle = {
242- height : `${ itemHeight } px`
271+ lineHeight : `${ this . itemHeight } px`
243272 } ;
244273
245274 return (
@@ -256,22 +285,7 @@ export default createComponent({
256285 class = { bem ( 'wrapper' ) }
257286 onTransitionend = { this . onTransitionEnd }
258287 >
259- { this . options . map ( ( option , index ) => (
260- < li
261- style = { optionStyle }
262- class = { [
263- 'van-ellipsis' ,
264- bem ( 'item' , {
265- disabled : isOptionDisabled ( option ) ,
266- selected : index === this . currentIndex
267- } )
268- ] }
269- domPropsInnerHTML = { this . getOptionText ( option ) }
270- onClick = { ( ) => {
271- this . onClickItem ( index ) ;
272- } }
273- />
274- ) ) }
288+ { this . genOptions ( ) }
275289 </ ul >
276290 </ div >
277291 ) ;
0 commit comments