I will have an attempt:
I try to use mvc-pattern to develop my application, since the implementation of all the material in one js file is pretty ugly. therefore, I decided to use one file for presentation and all materials representing the appearance, one file for processing the database (controller), especially SQL statements, and one file for the abstract data type (model).
short example:
view: viewConcerningObject.js
Ti.include('object.js'); var win = Ti.UI.currentWindow; var myObject = new object(); var myObjectName = Ti.UI.createLabel({ text:myObject.getName(); }); win.add(myObjectName);
model: object.js
Ti.include('controllerConceringObject.js'); function object(){ this.name = 'myInitialName'; this.getName(){ return this.name; }; this.setName(newName){ this.name = newName; }; this.updateNameFromDb(){ this.name = getNameFromDatabase(); }; }
controller: controllerConcerningObject.js
function getNameFromDataBase(){ var db = Ti.Database('objects'); var sql = 'SELECT name FROM objects'; var recordset = db.execute(sql); var name = recordset.field(0); recordset.close(); db.close(); return name; };
therefore, the folder structure may be as follows:
myProject: folderView (viewConcerningObject.js), folderModel (theDatabase.db, object.js), folderController (controllerConcerningObject.js).
mkind
source share