Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何用钛合金(经典)将数据从一个窗口传递到另一个窗口?_Javascript_Titanium - Fatal编程技术网

Javascript 如何用钛合金(经典)将数据从一个窗口传递到另一个窗口?

Javascript 如何用钛合金(经典)将数据从一个窗口传递到另一个窗口?,javascript,titanium,Javascript,Titanium,'MyHTTPlink(在我的代码中提到)包含一些餐厅名称、url、地址。使用此代码,我可以列出我表格中的所有餐厅名称和url。现在我想做的是,如何将表格行详细信息发送到下一个窗口(.js页)。餐厅url包含每个餐厅的许多菜单项。在下一页的表格行中列出菜单项。如何对其进行编码?“ var win = Titanium.UI.createWindow ({ backgorundColor: '#000'}); var tableview = Ti.UI.createTableView({

'MyHTTPlink(在我的代码中提到)包含一些餐厅名称、url、地址。使用此代码,我可以列出我表格中的所有餐厅名称和url。现在我想做的是,如何将表格行详细信息发送到下一个窗口(.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();
var-win=Titanium.UI.createWindow({backgorundColor:'#000'});
var tableview=Ti.UI.createTableView({
高度:'自动',
布局:'垂直',
前五名,
右:5,,
底部:5,左侧:5});
var数据=[];
var xhr=Ti.Network.createHTTPClient({
onload:function(){
警惕(“成功!”);
var json=json.parse(this.responseText);
for(var i=0;i
请检查下面的代码并在代码中使用。 你可以这样做

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”

也许这对你有帮助


谢谢,

除了MRT回答的正确且有效的代码外,您还可以使用以下代码避免使用url属性,如此处所建议的:

在您的代码中:

tableview.addEventListener('click',function(e){
    hotelWin = require('/yourpath/hotelpage');
    var hotelW = new hotelWin(e.row.title, e.row.id)
  });
在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.
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;

我建议您使用模块(require),因为您可以在构造函数中传递值。例如:var hostelwin=require('hotelpage')(e.row.title,data[e]);其中e.row.title是tableViewCell和data[e]的标题一个包含每个单元格数据的hashMap。如何在下一页使用e.row.title和id您有两个变量中的值。我更新了代码中的注释。@maxdangelo代码也工作得很好。但是,Satheesh使用该类型代码这就是为什么,我建议使用CreateWindow和currentWindow方法。这也很好,也很有效。取决于您你喜欢并执行你的任务……:)