Results 1 to 10 of 10
  1.    #1  
    Having a hard time trying to populate a list selector from the results returned from an SQL query.

    Here is my code. Any ideas what is wrong?

    Code:
    NewRoundAssistant.prototype.setupChoices = function(){
    
        this.selectorsModel = {currentCourse: ""}
        
        // Options for list selector choices:
        this.getCourses();    
    }
    
    NewRoundAssistant.prototype.getCourses = function(event) {
        db.transaction(
            (function(transaction) {
            transaction.executeSql("SELECT id, name FROM courses order by name;", [], 
            this.buildCourses.bind(this),this.errorCourses.bind(this)); 
        }).bind(this));
    }
    
    NewRoundAssistant.prototype.buildCourses = function(transaction, results) {
        var allcourses = [];
        //loop through the original data set & get the subset of items that have the filterstring 
        var i = 0;
        while (i <  this.results.length) {
            allcourses.push({
                label: this.results[i].name,
                value: this.results[i].id
            });
            i++;
        }
        this.courses = allcourses;
    }
  2.    #2  
    Can anyone please help on this ?
  3.    #3  
    Got this one working now
  4. #4  
    Woukd you mind giving us the solution? I am interested.

    Thank you.
  5.    #5  
    PREvision,

    Sure, no problem. Here is how I achieved it. Most of the code comes from the sample from the SDK.

    Code:
    NewRoundAssistant.prototype.setup = function() {
    
    	this.controller.listen('courseSelector', Mojo.Event.propertyChange, this.courseChanged.bindAsEventListener(this));
    	this.setupChoices();
    		this.controller.setupWidget('courseSelector', {label: $L('Course'), choices: this.courses, modelProperty:'currentCourse'}, this.selectorsModel);
    
    NewRoundAssistant.prototype.setupChoices = function(){
    	
    	this.selectorsModel = {currentCourse: "", currentTees: ""};
    	/* Obtain coruses list from local DB and populate the ListSelector */
    	this.courses = [];
    	this.getCourses();
    	/* Obtain coruses list from local DB and populate the ListSelector */
    }
    
    NewRoundAssistant.prototype.getCourses = function() {
    	db.transaction(
    		(function(transaction) {
            transaction.executeSql("Your SQL code here", [], 
    		this.buildCourses.bind(this),this.errorCourses.bind(this)); 
    	}).bind(this));
    }
    
    NewRoundAssistant.prototype.buildCourses = function(transaction, results) {
    	//loop through the original data set & get the subset of items that have the filterstring 
    
    	if (results.rows.length > 0) {
    		for (var i = 0; i < results.rows.length; i++) {
    			this.courses[i] = {
    				label: results.rows.item(i).name,
    				value: results.rows.item(i).id
    			};
    		}
    	}
    	else {
    		/* Display that no courses were found */
    	}
    }
  6. #6  
    Thank you.
  7. #7  
    One question to those using DB.
    Can I have a DB with data already in there installed when the app installs. If so, where do i store that DB, in what type of file and how do I create it?

    Sorry, I am a little confused about where the Db is stored.
    Last edited by PREvision; 07/30/2009 at 05:32 PM.
  8. #8  
    Anyone?
  9.    #9  
    PREVision, I am not sure about the answer to that either, but would be interested to know if that is possible.
  10. #10  
    The reason I am asking is that I am better at using SQL to query a DB than using JavaScript to get data from an array. So for example, if I want to create an app with a list of cooking receipe, I could tore everything in a DB rather than an array. But this means the DB contains the data when the app is install. It is not a new DB the user creat and then use as he opens the app.
    So back to my question, how do I create such a DB, where do I store it and kind of file is it?

Posting Permissions