Javascript 将Xml数据导入tableview
我问了一个类似的问题并得到了答案,现在我遇到了另一个颠簸。我基本上是想先在一个表视图中获取县的名称,然后当我按下一个县时,该县的所有城市都应该创建一个表视图,然后该市的所有公司都应该出现在一个表视图中,最后是一个窗口,其中有一些关于该公司的详细信息。这是我的密码: 致以最良好的祝愿! 菲利普 XML代码:Javascript 将Xml数据导入tableview,javascript,ios,xml,tableview,titanium-mobile,Javascript,Ios,Xml,Tableview,Titanium Mobile,我问了一个类似的问题并得到了答案,现在我遇到了另一个颠簸。我基本上是想先在一个表视图中获取县的名称,然后当我按下一个县时,该县的所有城市都应该创建一个表视图,然后该市的所有公司都应该出现在一个表视图中,最后是一个窗口,其中有一些关于该公司的详细信息。这是我的密码: 致以最良好的祝愿! 菲利普 XML代码: <?xml version="1.0" encoding="UTF-8"?> <food_company> <county> <countyn
<?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>
country.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();
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();
Ti.include('app_functions.js');
var win=tianium.UI.currentWindow;
//创建一个表来显示新闻提要--------------------------------
var itemsTable=Ti.UI.createTableView({
排名前:“11%”,
左:0,,
左图:“taxi.png”,
背景色:“#DCEEDC”,//E1E6EE
底部:“0%”,
//搜索:搜索栏,
filterAttribute:'searchFilter'
});
win.add(itemsTable);
//定义xmlFeed(您可以使用任何RSS源自定义此内容)
var xmlFeed=http://eventverket.nu/test/test5.xml';
//'http://83.254.164.137:1000/test.xml';
//创建新的HTTP客户端对象
var xhr=Ti.Network.createHTTPClient();
//此方法将处理远程数据
xhr.onload=函数(){
//创建一个xml对象
var xml=this.responseXML;
//创建一个数组,用于存储tableView的新闻项
var数据=[];
var数据=[];
var items=xml.documentElement.getElementsByTagName(“县”);
对于(var i=0;i
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();