In my code i am tring to display my sqlite db in vertual list and in that code in for loop you can see the commented alerts and they conform that the value i want is which i want from db.
now that value i want to show in vertual list.
I know the solution is like setup data in array and render it but how? can please replay with edit my code
/* Copyright 2009-2011 Hewlett-Packard Development Company, L.P. All rights reserved. */
enyo.kind({
name: "storage.SQLite",
kind: HeaderView,
components: [
{name: "createDBButton", kind: "Button", caption: "Create Database", onclick: "createDB"},
{name: "createTableButton", kind: "Button", caption: "Create TABLE1", onclick: "createTable"},
{name: "fillTableButton", kind: "Button", caption: "Insert a Row into TABLE1", onclick: "fillTable"},
{name: "queryButton", kind: "Button", caption: "Show TABLE1 Contents", onclick: "doQuery"},
{name: "results", kind: "HtmlContent"},
{kind: "VirtualList", name:"myVirtualList", style: "width: 500px; height: 200px;",
components: [
{kind: "Item", layoutKind: "HFlexLayout", components: [
{name: "caption1", flex: 1},
{name: "caption2", flex: 1},
]}
]
}
],
createDB: function() {
try {
this.db = openDatabase('SampleDB', '', 'Sample Data Store', 65536);
this.$.results.setContent("Created database SampleDB.");
}
catch (e)
{
this.$.results.setContent(e);
}
},
createTable: function() {
try {
this.nullHandleCount = 0;
//create table 1
var string = 'CREATE TABLE IF NOT EXISTS table1 (col1 TEXT NOT NULL DEFAULT "nothing", col2 TEXT NOT NULL DEFAULT "nothing");'
this.db.transaction(
enyo.bind(this,(function (transaction) {
//transaction.executeSql('DROP TABLE IF EXISTS table1;', []);
transaction.executeSql(string, [], enyo.bind(this,this.createTableDataHandler), enyo.bind(this,this.errorHandler));
}))
);
}
catch (e)
{
this.$.results.setContent(e);
}
},
fillTable: function() {
this.$.results.setContent('0');
this.nullHandleCount = 0;
var string = 'INSERT INTO table1 (col1, col2) VALUES (" Ajay "," value2 ");'
this.db.transaction(
enyo.bind(this,(function (transaction) {
transaction.executeSql(string, [], enyo.bind(this,this.createRecordDataHandler), enyo.bind(this,this.errorHandler));
}))
);
},
doQuery: function() {
// Query table1
var mytext = 'select * from table1;'
this.db.transaction(
enyo.bind(this,(function (transaction) {
transaction.executeSql(mytext, [], enyo.bind(this,this.setupRow), enyo.bind(this,this.errorHandler));
开发者_运维技巧 }))
);
},
createTableDataHandler: function(transaction, results)
{
this.$.results.setContent("Created TABLE1.");
},
createRecordDataHandler: function(transaction, results)
{
this.$.results.setContent("Inserted 1 record.");
},
setupRow: function(transaction, results)
{
var string = "";
try {
var list = [];
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
//alert(results.rows.item(i).col1);
//alert(results.rows.item(i).col2);
this.$.caption1.setContent(results.rows.item(i).col1);
this.$.caption2.setContent(results.rows.item(i).col1);
}
}
catch (e)
{
this.$.results.setContent(e);
}
},
errorHandler: function(transaction, error)
{
this.$.results.setContent('Error was '+error.message+' (Code '+error.code+')');
}
});
I think you need to use a virtual Repeater here: https://developer.palm.com/content/api/reference/enyo/enyo-api-reference.html#enyo.VirtualRepeater
Which has a number of options for callbacks - for example onSetupRow: "someMethod"
You need to call this method... which will populate each row of your grid.
What I do for my resultsset rightly or wrongly is in my override of Create, i will create a variable varResults = [];
I then call a method to query my data e.g.
onClickData: function(){
// Get some data
this.varResults = recordSet;
}
Does this help? p.s. I dont appreciate you emailing my personal email address and asking questions!
精彩评论