javascript - Titanium error in retrieving rows -
javascript - Titanium error in retrieving rows -
getting error when retrieving datas row using id , displaying in textfield in next page..and error rows getting deleted when passing id specific row..
here coding:
var info = []; var db = titanium.database.open('trip'); db.execute('create table if not exists newtrip (id integer primary key autoincrement, triplabel text,tripname text,destination text,fromdate text,todate text)'); //db.execute('insert newtrip(triplabel,tripname,destination,fromdate,todate) values(?,?,?,?,?)',"british museum","mytrip","london","12-10-2014","12-12-2014"); //db.execute('delete newtrip'); var resultrows = db.execute('select destination,fromdate,todate newtrip'); while (resultrows.isvalidrow()) { //var res= var row = ti.ui.createtableviewrow({ height : ti.ui.size, rightimage : '/images/right1.png', layout : 'absolute' }); var tripnamelabel = ti.ui.createlabel({ //text : 'buckingham palace', text : resultrows.fieldbyname('destination'), color : theme_style, font : { fontsize : '16dp', fontweight : 'bold' }, top : '10dp', left : '10dp', //right:'30dp' }); var gettablecount = resultrows.rowcount; (var = 0; < gettablecount; i++) { var data_edit = []; var imgedit = ti.ui.createbutton({ backgroundimage : '/images/list_edit.png', // left:'200dp', top : '20dp', width : wb, height : hb, // bottom:10, right : '20dp', onclick : "edit", rowid : resultrows.fieldbyname('id') }); if (resultrows.isvalidrow()) { imgedit.addeventlistener('click', function(e) { var db = titanium.database.open('trip'); if (e.source.onclick == "edit") { var x = db.execute('select * newtrip id=' + rowid); //alert(x); var createnewwindowback = require('ui/apppage5'); //the name of url wish move new createnewwindowback(e.source.rowid).open(); win.close(); } resultrows.close(); db.close(); }); } } (var = 0; < gettablecount; i++) { var imgdelete = ti.ui.createbutton({ backgroundimage : '/images/delete_ic.png', // left:'240dp', top : '20dp', width : wb, height : hb, //bottom:'20dp', right : '60dp', onclick : "delete", rowid : resultrows.fieldbyname('id') }); imgdelete.addeventlistener('click', function(e) { var db = titanium.database.open('trip'); if (e.source.onclick == "delete") { var x = db.execute('delete newtrip id=' + rowid); alert("you have clicked delete button"); } resultrows.next(); db.close(); }); } var fromdate = ti.ui.createlabel({ //text : '10.11.2014', text : resultrows.fieldbyname('fromdate'), color : 'black', font : { fontsize : '13dp', fontweight : 'bold' }, top : '40dp', left : '10dp', right : '10dp', bottom : '20dp' }); var dash = ti.ui.createlabel({ text : '-', color : 'black', font : { fontsize : '15dp', fontweight : 'bold' }, top : '40dp', left : '80dp', right : '10dp', bottom : '20dp' }); var todate = ti.ui.createlabel({ text : resultrows.fieldbyname('todate'), color : 'black', font : { fontsize : '13dp', fontweight : 'bold' }, top : '40dp', left : '90dp', right : '10dp', bottom : '20dp' }); row.add(tripnamelabel); row.add(imgedit); row.add(imgdelete); row.add(fromdate); row.add(dash); row.add(todate); row.classname = 'control'; data.push(row); resultrows.next(); } resultrows.close(); db.close(); triplistview.setdata(data);
i think not able fetch info according id field because fetch info in resultrows
variable :
var resultrows = db.execute('select destination,fromdate,todate newtrip');
so here not fetch id column. utilize @ :
rowid : resultrows.fieldbyname('id') // in : var imgedit
hence rowid
var imgedit
null/undefined. should modify select
query :
var resultrows = db.execute('select id,destination,fromdate,todate newtrip');
edit : under click listener of imgedit
have :
var x = db.execute('select * newtrip id=' + rowid);
but there no variable rowid
defined, hence error thrown. create next changes ( rowid
changed e.source.rowid
) :
var x = db.execute('select * newtrip id=' + e.source.rowid);
hope helps.
javascript titanium titanium-mobile
Comments
Post a Comment