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
The select and options are embedded in the markup.
html<label>
HTML
<input mbsc-input id="my-input" data-dropdown="true" />
</label>
<select id="my-select">
<option value="atl">Atlanta</option>
<option value="ber">Berlin</option>
<option value="bos">Boston</option>
<option value="chi">Chicago</option>
<option value="lon">London</option>
<option value="la">Los Angeles</option>
<option value="ny">New York</option>
<option value="par">Paris</option>
<option value="sf">San Francisco</option>
</select>
jsmobiscroll.select('#my-select', {
inputElement: document.getElementById('my-input'),
touchUi:
}); Pass the items to the data option if you are loading from the model or in case of item templating.
html<label>
Data object
<input mbsc-input id="my-select" data-dropdown="true" />
</label>
jsmobiscroll.select('#my-select', {
touchUi: ,
data: [
{ 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' }
]
}); The data loaded from a remote source needs to be passed to the data option as in the previous example.
html<label>
Remote data
<input mbsc-input id="my-select" data-dropdown="true" />
</label>
jsvar inst = mobiscroll.select('#my-select', {
touchUi:
});
mobiscroll.getJson('https://trial.mobiscroll.com/content/languages.json', function (resp) {
inst.setOptions({ data: resp });
}, 'jsonp'); mobiscroll.setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
mobiscroll.select('#demo-data-sources-html', {
inputElement: document.getElementById('demo-data-sources-html-input'),
});
mobiscroll.select('#demo-data-sources-object', {
data: [
{
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',
},
],
});
var inst = mobiscroll.select('#demo-data-sources-remote', {
inputElement: document.getElementById('demo-data-sources-html-input'),
});
mobiscroll.getJson('https://trial.mobiscroll.com/content/languages.json', function (resp) {
inst.setOptions({ data: resp });
});
<div class="mbsc-grid mbsc-form-grid">
<div class="mbsc-row">
<div class="mbsc-col-sm-12 mbsc-col-md-4">
<label>
HTML
<input mbsc-input id="demo-data-sources-html-input" data-dropdown="true" data-input-style="box" data-label-style="stacked" placeholder="Please select..." />
</label>
<select id="demo-data-sources-html">
<option value="atl">Atlanta</option>
<option value="ber">Berlin</option>
<option value="bos">Boston</option>
<option value="chi">Chicago</option>
<option value="lon">London</option>
<option value="la">Los Angeles</option>
<option value="ny">New York</option>
<option value="par">Paris</option>
<option value="sf">San Francisco</option>
</select>
</div>
<div class="mbsc-col-sm-12 mbsc-col-md-4">
<label>
Data object
<input mbsc-input id="demo-data-sources-object" data-dropdown="true" data-input-style="box" data-label-style="stacked" placeholder="Please select..." />
</label>
</div>
<div class="mbsc-col-sm-12 mbsc-col-md-4">
<label>
Remote data
<input mbsc-input id="demo-data-sources-remote" data-dropdown="true" data-input-style="box" data-label-style="stacked" placeholder="Please select..."></select>
</label>
</div>
</div>
</div>