The HTML for creating the list page requires the following simple elements:
A heading that reads Employee Directory
An onLoad
function in the body tag called buildEmployeeList
.
A span
element with an id of listSpan
.
You can find the HTML for the sample list page shown in Verifying download of the M-Business XML POD (database POD) to a device or emulator in the file index.html, which is available in DB_sample.zip file on the M-Business Anywhere Product Manuals page, referenced in Related publications.
The onLoad
function buildEmployeeList
builds an ordered list that contains the data from the avgoEmpDir database.
Initialize the M-Business XML POD.
Open the avgoEmpDir database with the read flag set.
Check for error.
Code for steps 1 – 3:
dbMgr = CreateObject("avantgo.db"); dbSet = dbMgr.open("avgoEmpDir", "r"); if(!dbSet) { //return an error } |
Find the span element using the built-in document
object in JavaScript.
Create an ordered list <ol> element and make it a child of the span element.
Code for steps 4 and 5:
span = document.getElementById("listSpan"); list = document.createElement("ol"); span.appendChild(list); |
Loop until the end of the data set is reached.
Create a list element and make it a child of the list
Create an anchor element.
Set the id of the anchor tag to the id of the record, since it is the primary key to retrieve database record. This passes the id into the onclick event.
Set the onclick event to the JavaScript function switchToDetail.
Create a string comprised of the first name, last name and phone number, then make the string a child of the anchor element.
Make the anchor element a child of the list element.
Move the data set pointer to the next record.
Code for steps 6 – 13:
while(!dbSet.ateof()) { var linktext; listelement = document.createElement("li"); list.appendChild(listelement); anchor = document.createElement("a"); anchor.id = dbSet.id; anchor.onclick = switchToDetail; |
var description = dbSet.firstname + " " + dbSet.lastname + " " + dbSet.phonenumber linktext = document.createTextNode(description); |
anchor.appendChild(linktext); listelement.appendChild(anchor); dbSet.moveNext(); } |
The switchToDetail
function shown above, creates a list where each list element is comprised of the data from a row in the avgoEmpDir data set.
The row data is represented as a link. When clicked, each link calls the switchToDetail
JavaScript function, to be discussed in more detail later. First, however, it is important to understand how information
is passed from one page to another in offline mobile applications.
function switchToDetail() { // the id of the anchor has the record id PropertiesDBSetValue("sessiondb", "currentid", this.id); // send the broswer to the detail page window.location = "/EmpDir/update_employee.html"; } |
You can use the M-Business XML POD to save the state between pages. In the Employee Directory example, you can save the key/value
pair that tells the detail page which employee information to display. The switchToDetail
function shown in the figure above, shows an example of saving the value of the anchor's ID (which was set to the record
id of the employee) in an on-device database called sessiondb and associating it with the key currentid.
After determining which employee's information you want to display, you call window.location
to switch M-Business Client to that detail page.
The code for the PropertiesDBSetValue
is included with the code for this example.
Send feedback about this page using email. | Copyright © 2008, iAnywhere Solutions, Inc. |