2012-09-03 36 views
0

我試圖根據特定數據庫字段的內容顯示或隱藏按鈕。我將該字段定義爲'文本',因爲該字段可能包含類似1-1或1-20或0的字段。如果字段(arref1)不等於0,那麼我想顯示我的按鈕。否則,隱藏按鈕。以下是我有這麼遠,但忽略了最低工作:顯示或隱藏基於數據庫中字段內容的按鈕

var resultRule = db.execute('SELECT arref1 FROM genrules WHERE title="'+client+'"'); 
if (resultRule!='0') { 

var appliedRule1 = Ti.UI.createButton({ 
title:' Applied Rule ' + rows.fieldByName('arref1') + '', 
bottom:120, 
left: 80, 
width: 'auto', 
height:40, 
borderRadius:5, 
textAlign: 'center', 
color:'#FFFFFF', 
backgroundColor:'#7b4336', 
backgroundSelectedColor:'#cc9933', 
backgroundImage: 'NONE', 
font:{fontSize:'20dp'} 
}); 
win.add(appliedRule1); 

appliedRule1.addEventListener('click',function(e) 
{ 

    var win = Ti.UI.createWindow({ 
     url: 'appliedruledetail.js', 
     title:' Applied Rule' + rows.fieldByName('arref1') + '' 
    }); 

    var client = '' + rows.fieldByName('genrule') + '' ; 
    win.client = client; 
    Ti.UI.currentTab.open(win); 
} 

); 
} else{}; 

回答

2

db.execute返回Titanium.DB.ResultSet(這是一個對象),而不是字符串。

這裏是你如何使用結果集:

// Get the row with execute, returns a resultSet 
var row = db.execute('SELECT * FROM genrules WHERE title="'+client+'"'); 
// Make sure its a valid row 
if (row.isValidRow()){ 
    // Now get the field from the current row 
    if(row.fieldByName('arref1') != '0') { 
     // Add your button here 
    } 
} 
row.close(); // Close the result set since were done with it 

I heavily borrowed from this example in the documentation

+0

我認爲我們已經得到了郵件在同一時間。即將回答此問題;) –

+0

非常感謝,我瞭解了ResultSet並與他們合作。 – dnevels

相關問題