Populating the picker
The select component takes care of rendering data in a scrollable and consumable way for the user. The date can be passed a couple of different ways:
- Inline HTML, embedded in the markup - This is good if you only have a couple of static options.
- With the
dataoption - If you want to load model data this is the way to do it. This is the way to populate the select if you want to create a custom item template. - Remote data - Load it through the
dataoption from a remote api/data source.
Demo
Data object
Pass the items to the data option if you are loading from the model or in case of item templating.
<script setup>
const myData = [
{ text: 'Atlanta', value: 'atl' },
{ text: 'Berlin', value: 'ber' },
{ text: 'Boston', value: 'bos' },
{ text: 'Chicago', value: 'chi' },
{ text: 'London', value: 'lon' },
{ text: 'Los Angeles', value: 'la' },
{ text: 'New York', value: 'ny' },
{ text: 'Paris', value: 'par' },
{ text: 'San Francisco', value: 'sf' }
]
</script>
<template>
<MbscSelect
:data="myData"
:touchUi=" "
/>
</template>
Remote data
The data loaded from a remote source needs to be passed to the data option as in the previous example.
<script setup>
const remoteData = ref([])
onMounted(() => {
getJson('https://trial.mobiscroll.com/content/languages.json',
(resp) => {
remoteData.value = resp
})
})
</script>
<template>
<MbscSelect
:data="remoteData"
:touchUi=" "
/>
</template>
SFC JSSFC TS
<script setup>
import { getJson, MbscPage, MbscSelect, setOptions } from '@mobiscroll/vue'
import { onMounted, ref } from 'vue'
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
})
const remoteData = ref([])
const myData = [
{
text: 'Atlanta',
value: 'atl'
},
{
text: 'Berlin',
value: 'ber'
},
{
text: 'Boston',
value: 'bos'
},
{
text: 'Chicago',
value: 'chi'
},
{
text: 'London',
value: 'lon'
},
{
text: 'Los Angeles',
value: 'la'
},
{
text: 'New York',
value: 'ny'
},
{
text: 'Paris',
value: 'par'
},
{
text: 'San Francisco',
value: 'sf'
}
]
onMounted(() => {
getJson('https://trial.mobiscroll.com/content/languages.json', (resp) => {
remoteData.value = resp
})
})
</script>
<template>
<MbscPage>
<div class="mbsc-grid mbsc-form-grid">
<div class="mbsc-row">
<div class="mbsc-col-sm-12 mbsc-col-md-6">
<MbscSelect
:data="myData"
label="Data object"
labelStyle="stacked"
inputStyle="box"
placeholder="Please select..."
/>
</div>
<div class="mbsc-col-sm-12 mbsc-col-md-6">
<MbscSelect
:data="remoteData"
label="Remote data"
labelStyle="stacked"
inputStyle="box"
placeholder="Please select..."
/>
</div>
</div>
</div>
</MbscPage>
</template>
<script setup lang="ts">
import { getJson, MbscPage, MbscSelect, setOptions } from '@mobiscroll/vue'
import { onMounted, ref } from 'vue'
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
})
const remoteData = ref([])
const myData = [
{
text: 'Atlanta',
value: 'atl'
},
{
text: 'Berlin',
value: 'ber'
},
{
text: 'Boston',
value: 'bos'
},
{
text: 'Chicago',
value: 'chi'
},
{
text: 'London',
value: 'lon'
},
{
text: 'Los Angeles',
value: 'la'
},
{
text: 'New York',
value: 'ny'
},
{
text: 'Paris',
value: 'par'
},
{
text: 'San Francisco',
value: 'sf'
}
]
onMounted(() => {
getJson('https://trial.mobiscroll.com/content/languages.json', (resp) => {
remoteData.value = resp
})
})
</script>
<template>
<MbscPage>
<div class="mbsc-grid mbsc-form-grid">
<div class="mbsc-row">
<div class="mbsc-col-sm-12 mbsc-col-md-6">
<MbscSelect
:data="myData"
label="Data object"
labelStyle="stacked"
inputStyle="box"
placeholder="Please select..."
/>
</div>
<div class="mbsc-col-sm-12 mbsc-col-md-6">
<MbscSelect
:data="remoteData"
label="Remote data"
labelStyle="stacked"
inputStyle="box"
placeholder="Please select..."
/>
</div>
</div>
</div>
</MbscPage>
</template>