The problem is that the condition in titanium alloy
I have two picklists in my application, both are dynamic values coming from the DB. The values in the second picklist are displayed based on the value selected in the first picklist. Therefore, change the event of the first picklist so that the values of the second picklist should change dynamically without refreshing the page.
My code looks like this:
Controller:
$.picker.addEventListener('change',function(e){
languageid = e.row.title;
alert("language is : "+ languageid);
movie.fetch({query: "SELECT * FROM movies WHERE id = '"+languageid+"';"});
var column = Ti.UI.createPickerColumn();
movie.each(function(model){
var row = Ti.UI.createPickerRow({
title: model.get("movieName")
});
column.addRow(row);
});
$.picker1.columns = [column];
});
View:
<Alloy>
<Collection src="UserLanguage"/>
<Collection src="movies"/>
<Window class="container">
<Picker id="picker"/>
<Picker id="picker1"/>
</Window>
</Alloy>
Style:
".container": {
backgroundColor:"black"
}
"#picker": {
width: '90%',
top: '25dp'
}
"#picker1": {
width: '90%',
top: '100dp'
}
Model
exports.definition = {
config : {
"columns": {
"id": "text",
"movieName": "text"
},
"adapter": {
"type": "sql",
"collection_name": "movies"
}
}
};
Screenshot
The spawn selection rule has been checked, but no text is displayed. What for?
source to share
OK, start over, because the current solution is too messy ...
View: (make sure you have models / Movies.js)
<Alloy>
<Collection src="UserLanguage"/>
<Collection src="Movies"/>
<Window class="container">
<Picker id="picker"/>
<Picker id="picker1"/>
</Window>
</Alloy>
Controller: (the problem was @Coyote fetching data from the movie
not table movies
). So it should look like this:
var movies = Alloy.Collections.Movies;
$.picker.addEventListener("change", function(e) {
var column = Ti.UI.createPickerColumn();
movies.fetch({
query: {
statement: "SELECT * FROM movies WHERE id = ?;",
params: [e.row.title] // How can be `title` an id?
}
});
movies.each(function(model) {
var row = Ti.UI.createPickerRow({
title: model.get("movieName")
});
column.addRow(row);
});
$.picker1.columns = [column];
});
source to share
Just use the request parameter passed to the fetch function:
$.picker.addEventListener('change',function(e){
languageid = e.row.title;
//alert("language is : "+ languageid);
movie.fetch({query: "SELECT * FROM movie WHERE id = '"+languageid+"';"});
var column = Ti.UI.createPickerColumn();
movie.each(function(model){
var row = Ti.UI.createPickerRow({
title: model.get("movieName");
});
column.addRow(row);
});
$.picker1.columns = [column];
});
source to share