向Titanium添加查询
Adding Query to Titanium
我使用Titanium列出特定产品中可用的数量,并使用Query"选择product_name,SUM(product_quantity)FROM mobile_product GROUP BY product_name"。。
在将此查询实现到Titanium JS时,我感到困惑。
我的钛代码是
var currentWin = Ti.UI.currentWindow;
var sendit = Ti.Network.createHTTPClient();
sendit.open('GET', 'http://localhost/mobileapp/productread.php');
sendit.send();
sendit.onload = function(){
var json = JSON.parse(this.responseText);
var json = json.mobile_product;
var picker = Ti.UI.createPicker();
// turn on the selection indicator (off by default)
picker.selectionIndicator = true;
var data = [];
var pos;
for (pos=0; pos < json.length; pos++) {
data.push (Ti.UI.createPickerRow({title:''+ json[pos].product_name + '',custom_item:'b'}));
}
picker.add(data);
currentWin.add(picker);
//var rw = db.execute("SELECT product_name, SUM(product_quantity)FROM mobile_product GROUP BY product_name");
picker.addEventListener("change", function(e){
Ti.API.info(''+ json[pos].product_name + '');
})
};
请有人帮我如何在这段代码中使用这个查询。。。我正在使用JSON从PHPMyAdmin进行解析。。。。。
重读你的问题后,你实际上在问几个关键问题。您在问我如何将数据输入数据库,然后如何对该数据库执行查询。
创建数据库:
var db = Ti.Database.open('MyDatabase');
db.execute('CREATE TABLE IF NOT EXISTS [mobile_product](id INTEGER, product_name TEXT, product_quantity INTEGER');
db.close();
加载数据库:
var json = JSON.parse(this.responseText);
for(var i=0; json.length; i++){
var product = json[i];
addProductToDatabase(product);
}
function addProductToDatabase(_args){
var db = Ti.Database.open('MyDatabase');
var result = db.execute('INSERT INTO mobile_product(product_name, product_quantity) VALUES (?, ?)', _args.product_name, _args.product_quatity);
db.close();
}
result = db.execute("SELECT product_name, SUM(product_quantity)FROM mobile_product GROUP BY product_name");
var myList = [];
while(result.isValidRow()){
myList.push({
product_name: result.fieldByName('product_name'),
product_quantity: result.fieldByName('product_quantity')
}];
result.next();
}
result.close();
db.close();
var data = [];
for (i=0; i<myList.length; i++) {
data.push (Ti.UI.createPickerRow({title:''+ myList[i].product_name + '',custom_item:'b'}));
}
picker.add(data);
相关文章:
- 将数据库中的超链接添加到查询结果
- 我想将查询字符串变量添加到JSON名称/值对中
- 新手查询动态添加属性
- 用于添加边缘的gremlin服务器查询
- 添加行并运行多个mySQL查询
- iron路由器将参数添加到字符串中,并添加一个查询
- 循环遍历数组,并在javascript中向sql查询添加参数
- 如何将媒体查询添加到 Jquery 中
- j查询添加十进制数
- j查询添加必填项到输入字段
- MongoDB findAndModify() 将查询添加到更新子句
- j查询添加 在键事件 Enter 上,使用 将其发送到后端
- 将浏览器大小查询添加到超大插件javascript文件中
- 向BreezeJS查询添加扩展子句后,EntityAspect属性仍然无效
- 如何使用连接操作查询添加日期选择器代码
- 如何将查询添加到具有多个加载器的webpack加载器中
- j查询添加自动链接到 href 属性
- 如何使用gwt-rpc将html/js查询添加到gwt应用程序
- 使用媒体查询添加类或其他属性
- asp.net :: J 查询 :: 使用 J 查询添加新元素