0
真的是一个JavaScript问题,但这里是我的代码........我真的很感谢一些帮助。自从我参加编码战壕以来,这个时间太长了。这是我的代码。Appcelerator/Javascript使用变量作为例程语法问题
我想使loadtravelurl成为一个函数,我可以从多个地方调用。
下面这三行是我的问题。 win2.title = title; win2.add(tv); tab2.open(webwin);
我希望能够在loadelectronicsurl函数中传递变量,在这里我可以动态地更改win2.title和win2.add(tv)中的文本win2。也想要用tab2做同样的事情。我知道它可以完成,只是有几年的时间,并忘记了如何在JavaScript中这样做。
以下是完整的代码,非常感谢您的帮助!
function loadelectronicsurl(){
var WindowWidth = Ti.Platform.displayCaps.platformWidth;
var WindowHeight = Ti.Platform.displayCaps.platformHeight;
var xhr = Titanium.Network.createHTTPClient();
xhr.open('GET',electronicsurl);
var data = [];
var WindowWidth = Ti.Platform.displayCaps.platformWidth;
xhr.onload = function() {
//Ti.API.info(this.responseText);
var xml = this.responseXML;
var channel = xml.documentElement.getElementsByTagName("channel");
var title = channel.item(0).getElementsByTagName("title").item(0).text;
win2.title = title;
var items = xml.documentElement.getElementsByTagName("item");
for (var i=0;i<items.length;i++) {
var this_post_title = items.item(i).getElementsByTagName("title").item(0).text;
var post_link = items.item(i).getElementsByTagName("link").item(0).text;
var row = Ti.UI.createTableViewRow({height:'auto',width:WindowWidth,top:0,hasChild: false});
var post_title = Ti.UI.createLabel({
text: this_post_title,
textAlign:'left',
left:0,
height:40,
font:{fontFamily:'Arial',fontSize:12},
width:'auto',
top:3,
color: 'black'
});
row.add(post_title);
row.link = post_link;
data.push(row);
}
var tv = Titanium.UI.createTableView({
data:data,
top:0,
width:WindowWidth,
height:WindowHeight
});
win2.add(tv);
tv.addEventListener('click',function(e) {
var webwin = Titanium.UI.createWindow({
url: 'showweb.js',
backgroundColor: '#fff',
myurl: e.rowData.link
});
tab2.open(webwin);
});
};
xhr.send();
}