admin管理员组文章数量:1399823
i'm new to appcelerators titanium and javascript and i'm interested in coding an iphone app. i recognized that there is a need of "many" code for creating the UI. that's no problem so far, but i tend to separate that code from my application logic wisely. what are the best practices?
[update] tweetanium is a great example how to structure a titanium mobile application
i'm new to appcelerators titanium and javascript and i'm interested in coding an iphone app. i recognized that there is a need of "many" code for creating the UI. that's no problem so far, but i tend to separate that code from my application logic wisely. what are the best practices?
[update] tweetanium is a great example how to structure a titanium mobile application
Share Improve this question edited Jan 30, 2012 at 12:59 mkind asked Sep 9, 2010 at 10:10 mkindmkind 2,0432 gold badges20 silver badges25 bronze badges2 Answers
Reset to default 4ok, i just found a cool practice.
i include the con_file.js with the application logic the view_file.js with
Titanium.include('../controller/con_file.js');
now i'm able to access the hole data structure.
i'll have a try:
i tend to use the mvc-pattern for developing my application since implementing all stuff in one single js-file is quite ugly. so i decided to use one file for the view and all the stuff concering the look-and-feel, one file for the database handling (the controller), especially the sql-statements, and one file for the abstract data type (the model).
a 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;
};
so the folder structure could be like this:
myProject: folderView(viewConcerningObject.js), folderModel(theDatabase.db,object.js), folderController(controllerConcerningObject.js).
本文标签: user interfaceseparation of logic and UI in titanium (javascript)Stack Overflow
版权声明:本文标题:user interface - separation of logic and UI in titanium (javascript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744225491a2596067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论