如何将数据从一个窗口传递到另一个钛(经典)?
'MyHTTPlink(在我的代码中提到)包含一些餐馆名称,网址,地址。使用此代码我列出了餐厅名称和网址中的所有餐厅名称和网址。 (.js文件页)。餐厅的URL包括很多对每个餐厅的菜单项。列出表行下页上的菜单项。如何代码?”如何将数据从一个窗口传递到另一个钛(经典)?
var win = Titanium.UI.createWindow ({ backgorundColor: '#000'});
var tableview = Ti.UI.createTableView({
height:'auto',
layout:'vertical',
top:5,
right:5,
bottom:5, left:5 });
var data = [];
var xhr = Ti.Network.createHTTPClient ({
onload: function() {
alert("success!");
var json = JSON.parse(this.responseText);
for (var i = 0; i < json.connectionResponses.length; i++) {
var row = Ti.UI.createTableViewRow({
height: 60,
});
var restLabel = Ti.UI.createLabel({
text: json.connectionResponses[i].restaurantName,
height: 'auto',
left:54,
top: 5,
font:{ fontSize:20 }
});
var connLabel = Ti.UI.createLabel({
text: json.connectionResponses[i].connectingurl,
height: 'auto',
left:54,
bottom:5,
font:{ fontSize:14 }
});
var image = Titanium.UI.createImageView({
image:'images/menu_icon.png',
top:4,
left:0,
height:45,
width:41
});
row.add(restLabel);
row.add(connLabel);
row.add(image);
data.push(row);
}
tableview.setData(data);
},
onerror: function() {
alert('There was an error retrieving the remote data. Try again.');
}
//timeout:5000
});
xhr.open("GET", "http:MYHTTPlink");
xhr.send();
tableview.addEventListener('click',function(e){
//alert("RS Name : " +e.row.title);
var winn = Ti.UI.createWindow({ url:'hotelpage.js'});
winn.open();
//var hostelwin = require('hotelpage').gethotelWin;
//var newwin = new hotelwin();
//newwin.open();
});
win.add(tableview);
win.open();
请只勾选下面的代码并使用你的代码。 你可以这样执行你的工作。
tableview.addEventListener('click',function(e){
//alert("RS Name : " +e.row.title);
var winn = Ti.UI.createWindow({
url:'hotelpage.js',
row_title : e.row.title,
all_info: e.row,
});
winn.open();
//var hostelwin = require('hotelpage').gethotelWin;
//var newwin = new hotelwin();
//newwin.open();
});
和“热elpage.js”
var curtWind = Ti.UI.currentWindow;
// Get Data like this
var title = curtWind.row_title;
var allData = curtWind.all_info;
// and you can use as per your requirement.
可能这有助于您,
感谢,
感谢您的代码。它的工作.. – 2014-09-19 14:07:31
总是欢迎的家伙。 :) – MRT 2014-09-19 14:14:13
除了什么MRT回答是正确的,工作的,你可以使用此代码,避免这里推荐使用url属性:Titanium 3.X documentation
在您的代码:
tableview.addEventListener('click',function(e){
hotelWin = require('/yourpath/hotelpage');
var hotelW = new hotelWin(e.row.title, e.row.id)
});
在hotelpage.js
function external(title, id) {
var hotelPageWin = Titanium.UI.createWindow({
//properties here
});
//You have available here two variables:
//title with assigned the value of e.row.title
//id with assigned the value of e.row.id
hotelPageWin.open();
return hotelPageWin;
};
module.exports = external;
如何使用下一页的e.row.title和id – 2014-09-21 04:21:36
您有两个变量的值。我更新了代码中的评论。 – maxdangelo 2014-09-21 08:15:30
@maxdangelo代码也是N的好方法。但是,Satheesh使用该类型的代码就是为什么,我建议使用CreateWindow和currentWindow方法。而且这也是很好的和工作。取决于你喜欢什么和执行你的任务.... :) – MRT 2014-09-22 05:57:41
我建议你使用模块(要求),由于你可以在构造函数传递值。例如:var hostelwin = require('hotelpage')(e.row.title,data [e]);其中e.row.title是tableViewCell的标题,data [e]是包含每个单元格数据的hashMap。 – 2014-09-19 11:13:04