Problem is when I’m trying list cities dynamically and then trying to set values as selected. I have updated the question. Please see the example below:
methods: {
markCity: function( objState ) {
var city = objState.selectedCity;
var area = city.split(', ');
// set city
var smartSelectCity = app.smartSelect.get('.smart-city');
smartSelectCity.setValue(area);
}
}
geting data from the backend/api: (in this case i use a timeout to simulate the ajax call, but its the same):
setTimeout(() => {
// this part is equal to your response
// app.request.promise.post('http://localhost/f7restful/api/get_city', {cid: country_id} ).then( res => { })
// so res = ajaxResult
let ajaxResult = [{
name: 'Dublin'
}, {
name: 'Cork'
}, {
name: 'Galway'
}, {
name: 'Limerick'
}]
let selectedCity = 'Dublin, Galway'
let area = selectedCity.split(', ')
// Here i assign the new data (res) to the template data. the setState will tell f7 to re-render the component. so AFTER the setState, a callback is called.
// So when the callback is called, we know that f7 has already rendered the component with the dinamically generated options.
// Now we need to asign the selected options.
vm.$setState({
city: ajaxResult
}, () => {
let smartSelectCity = vm.$app.smartSelect.get('.smart-city');
smartSelectCity.setValue(area)
})
}, 750)
Oh sorry, I didn’t see the fiddle link. It was hide. Now I can see your code and specially the anonymous function used as callback for $setState. I didn’t try this yet. But hopeful this will work.