You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
< docs >
-- -
order : 4
title :
zh - CN : 自定义渲染行数据
en - US : Custom datasource
-- -
# # zh - CN
自定义渲染每一个 Transfer Item , 可用于渲染复杂数据 。
# # en - US
Custom each Transfer Item , and in this way you can render a complex datasource .
< / docs >
< template >
< a -transfer
v -model :target-keys ="targetKeys"
:data-source ="mockData"
: list -style = " {
width : ' 300px ' ,
height : ' 300px ' ,
} "
@change ="handleChange"
>
< template # render = "item" >
< span class = "custom-item" style = "color: red" > { { item . title } } - { { item . description } } < / span >
< / template >
< / a - t r a n s f e r >
< / template >
< script lang = "ts" setup >
import { ref , onMounted } from 'vue' ;
interface MockData {
key : string ;
title : string ;
description : string ;
chosen : boolean ;
}
const mockData = ref < MockData [ ] > ( [ ] ) ;
const targetKeys = ref < string [ ] > ( [ ] ) ;
onMounted ( ( ) => {
getMock ( ) ;
} ) ;
const getMock = ( ) => {
const keys = [ ] ;
const mData = [ ] ;
for ( let i = 0 ; i < 20 ; i ++ ) {
const data = {
key : i . toString ( ) ,
title : ` content ${ i + 1 } ` ,
description : ` description of content ${ i + 1 } ` ,
chosen : Math . random ( ) * 2 > 1 ,
} ;
if ( data . chosen ) {
keys . push ( data . key ) ;
}
mData . push ( data ) ;
}
mockData . value = mData ;
targetKeys . value = keys ;
} ;
const handleChange = ( keys : string [ ] , direction : string , moveKeys : string [ ] ) => {
console . log ( keys , direction , moveKeys ) ;
} ;
< / script >