Results 1 to 2 of 2
  1.    #1  
    my app 4 different scenes that use 3 listselectors per scene. The code is practically identical except the values are pulled from different tables and store different data.

    I am setting up a class assistant to setup each widget and load the data.

    So anyways, since generating each widget is generic like so:

    ListAssistant.prototype.SetupList = function(scene,listobject,table,field)
    {
    this.db = openDatabase('PTS', '', 'PTS', 65536);
    this.scene = scene;
    this.listobject = listobject;
    this.table = table;
    this.field = field;
    this.listarray = [{
    value: " ",
    label: " ",
    }];
    this.scene.controller.setupWidget(listobject, {
    label: $L('>'),
    choices: this.listarray ,
    modelProperty: 'value'
    },
    this.scene.model = {
    value: '',
    disabled: false,
    });

    var mytext = "select rowid, " + field + ", isdefault from " + table + ";";
    this.db.transaction((function(transaction) {
    transaction.executeSql(mytext, [], this.LoadList.bind(this), this.errorHandler.bind(this));
    }).bind(this));
    }

    all of that works, then my LoadList function is like so:

    ListAssistant.prototype.LoadList = function(transaction,results) {


    // Handle the results
    var string = "";
    try {
    var list2 = [];
    var field = this.field;
    for (var i = 0; i < results.rows.length; i++) {
    var row = results.rows.item(i);
    var isrowdefault = row["IsDefault"];
    var obj = this.scene.controller.get(this.listobject);

    this.listarray.push({
    value: row["rowid"],
    label: row[field],
    });
    if (isrowdefault == "1") {
    this.scene.controller.get(this.listobject).model.value = row["rowid"];
    }
    }
    //update the list widget
    this.scene.controller.get(listobject).choices.push({
    value: "N",
    label: "New " + this.field,
    });
    this.listarray.clear();

    Object.extend(this.listarray, list2);
    this.scene.controller.modelChanged(this.scene.controller.get(this.listobject).model, this.scene);
    }
    catch(e) {
    console.log(e);
    }
    }

    now, I'm having trouble accessing the listobject model in the LoadList ..

    I obviously know how to do this by setting up variables for each model and calling that way ..

    but I think there is a way to access the model this way, isn't there? This is how I'd want to access the selected value from the page:

    $('mylistobject').model.value;

    anybody have any idea how to access that object's model without using the named variable used in the widget setup?
  2.    #2  
    ok, well, after 3 or 4 hrs of messing around, I have figured it out ..

    $('ListObject')._mojoController.model.value
    and
    $('ListObject')._mojoController.attributes.choices

    I have 3 sql lite tables that store my list values, and I can add and remove as pleases.. they have rowid, fieldname, isdefault.

    I am now setting up each list on each page's assistant via 1 line:

    new ListAssistant().SetupList(this,"Games","Game");

    now, I have to call the assistant the way i did above due to palm's asynchronous db calls...

    I tried this first:
    this.ListAssistant = new ListAssistant();
    this.ListAssistant.SetupList(this,"Games","Game");
    this.ListAssistant.SetupList(this,"Locations","Location");

    that would wipe out the values in the first list and only add to the second. This is due to the asynchronous nature of webos and html 5 db engines.

    below is the ListAssistant class:


    var ListAssistant = Class.create({
    initialize: function() {
    // Always save static bound references to member functions
    this.db = openDatabase('PTS', '', 'PTS', 65536);
    this.scene = null;
    this.listobject = null;
    this.table = null;
    this.field = null;
    this.model = null;
    },
    SetupList: function(scene, listobject, field) {
    //named list object in html the same as the table.
    this.db = openDatabase('PTS', '', 'PTS', 65536);
    this.scene = scene;
    this.listobject = listobject;
    this.field = field;

    this.scene.controller.setupWidget(listobject, {
    label: $L('>'),
    choices: [{
    value: " ",
    label: " ",
    }],
    modelProperty: 'value'
    },
    {
    disabled: false,
    value: ''
    });

    var mytext = "select RowID, " + field + ", IsDefault from " + listobject + ";";
    console.log(mytext);

    this.db.transaction((function(transaction) {
    transaction.executeSql(mytext, [], this.LoadList.bind(this), this.errorHandler.bind(this));
    }).bind(this));
    },
    LoadList: function(transaction, results, listobject) {
    // Handle the results
    var string = "";
    console.log(this.listobject);
    var obj = this.scene.controller.get(this.listobject);

    obj._mojoController.attributes.choices.clear();
    try {
    var field = this.field;
    var list = [];
    console.log(results.rows.length);
    for (var i = 0; i < results.rows.length; i++) {
    var row = results.rows.item(i);
    var isrowdefault = row["IsDefault"];

    list.push({
    value: row["rowid"],
    label: row[field]
    });
    if (isrowdefault == "1") {
    obj._mojoController.model.value = row["rowid"];
    }
    }
    //update the list widget
    list.push({
    value: "N",
    label: "New " + field,
    });
    obj._mojoController.attributes.choices = list;
    this.scene.controller.modelChanged(obj._mojoController.model, this.scene);
    }
    catch(e) {
    console.log(e);
    }
    },
    errorHandler: function() {}
    });





    well now, my brain hurts, but i am able to wipe out 3 functions and a bunch of lines of code from each page!

Posting Permissions