我问了一个类似的问题并得到了答案,现在我又来到了路上。我基本上试图在一个桌面视图中首先获得县名,然后当我按下一个县时,该县的所有城市都应该创建一个桌面视图,然后该城市中的所有公司都应该出现在tableview,最后是一个窗口,里面有关于公司的一些细节。这是我的代码:
祝你好运! 菲利普
XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<food_company>
<county>
<countyname>New York</countyname>
<city>
<cityname>New York City</cityname>
<restaurant>
<name>Dinos pizzeria</name>
<phone>01111111</phone>
<location>broadway1</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria2</name>
<phone>01111111</phone>
<location>broadway2</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria3</name>
<phone>01111111</phone>
<location>broadway3</location>
</restaurant>
</city>
<countyname>Baldwin County</countyname>
<city>
<cityname>Bay Minette</cityname>
<restaurant>
<name>Dinos pizzeria</name>
<phone>01111111</phone>
<location>broadway1</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria2</name>
<phone>01111111</phone>
<location>broadway2</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria3</name>
<phone>01111111</phone>
<location>broadway3</location>
</restaurant>
</city>
</lan>
</food_company>
app.js代码:
Titanium.UI.setBackgroundColor('#E1E6EE');
// create base UI tab and root window
var win1 = Titanium.UI.createWindow({
statusBarStyle: Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
tintColor: '#FFF',
backgroundColor:'#E1E6EE',
url: 'lan.js',
tabBarHidden: true,
navBarHidden: true
});
win1.open();
county.js代码:
Ti.include('app_functions.js');
var win = Titanium.UI.currentWindow;
// create a table to display news feeds--------------------------------
var itemsTable = Ti.UI.createTableView({
top : '11%',
left : 0,
leftImage : 'taxi.png',
backgroundColor : '#DCEEDC', //E1E6EE
bottom : '0%',
// search : searchBar,
filterAttribute : 'searchFilter'
});
win.add(itemsTable);
// define xmlFeed (you can customize this with any RSS feed)
var xmlFeed = 'http://eventverket.nu/test/test5.xml';
//'http://83.254.164.137:1000/test.xml';
// create a new HTTP client object
var xhr = Ti.Network.createHTTPClient();
// this method will process the remote data
xhr.onload = function() {
// create an xml object
var xml = this.responseXML;
// create an array that will store news items for our tableView
var data = [];
var data = [];
var items = xml.documentElement.getElementsByTagName("county");
for (var i=0; i<items.length; i++) {
var row = Ti.UI.createTableViewRow({
title: items.item(i).getTextContent()
});
data.push(row);
}
itemsTable.data = data;
// when the user clicks on a row
itemsTable.addEventListener('click', function(e) {
// NEW WINDOW
var newWindow = Titanium.UI.createWindow({
backgroundColor : '#DCEEDC', //E1E6EE
statusBarStyle : Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
font : fonts[16]['normal'],
url : "stad.js",
//backButtonTitle: 'Back',
//title: e.source.title,
tabBarHidden : true,
navBarHidden : true,
tintColor : '#FFF'
});
newWindow.open();
});
};
// this method will be called if there is an error in accessing the data
xhr.onerror = function() {
// hide activity indicator
activityIndicator.hide();
// display error
alert(this.status + ': ' + this.statusText);
return false;
};
// open the remote feed
xhr.open('GET', xmlFeed);
// execute the call to the remote feed
xhr.send();
city.js代码:
Ti.include('app_functions.js');
var newWin = Titanium.UI.currentWindow;
// create a table to display news feeds--------------------------------
var itemsTable = Ti.UI.createTableView({
top : '11%',
left : 0,
leftImage : 'taxi.png',
backgroundColor : '#DCEEDC', //E1E6EE
bottom : '0%',
// search : searchBar,
filterAttribute : 'searchFilter'
});
win.add(itemsTable);
// define xmlFeed (you can customize this with any RSS feed)
var xmlFeed = 'http://eventverket.nu/test/test5.xml';
//'http://83.254.164.137:1000/test.xml';
// create a new HTTP client object
var xhr = Ti.Network.createHTTPClient();
// this method will process the remote data
xhr.onload = function() {
// create an xml object
var xml = this.responseXML;
// create an array that will store news items for our tableView
var data = [];
var items = xml.documentElement.getElementsByTagName("city");
for (var i=0; i<items.length; i++) {
var row = Ti.UI.createTableViewRow({
title: items.item(i).getTextContent() //
});
data.push(row);
}
itemsTable.data = data;
// when the user clicks on a row
itemsTable.addEventListener('click', function(e) {
// NEW WINDOW
var newWindow = Titanium.UI.createWindow({
backgroundColor : '#DCEEDC', //E1E6EE
statusBarStyle : Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
font : fonts[16]['normal'],
url : "stad.js",
//backButtonTitle: 'Back',
//title: e.source.title,
tabBarHidden : true,
navBarHidden : true,
tintColor : '#FFF'
});
});
};
// this method will be called if there is an error in accessing the data
xhr.onerror = function() {
// hide activity indicator
activityIndicator.hide();
// display error
alert(this.status + ': ' + this.statusText);
return false;
};
// open the remote feed
xhr.open('GET', xmlFeed);
// execute the call to the remote feed
xhr.send();