如何将数据从一个窗口传递到另一个窗口(经典)?

时间:2014-09-19 10:26:15

标签: javascript titanium

' MyHTTPlink(在我的代码中提到)包含一些餐馆名称,网址,地址。使用此代码列出我桌子中的所有餐馆名称和网址。现在我想做,如何发送表格行详细信息到下一个窗口(.js页面)。餐厅网址包含每个餐厅的菜单项。在下一页的表格行中列出菜单项。如何编码?'

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();

2 个答案:

答案 0 :(得分:0)

请检查以下代码并在您的代码中使用。 你可以这样做你的工作。

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();
      });

和“hotelpage.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.

可能这对你有帮助,

谢谢,

答案 1 :(得分:0)

除了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;
相关问题