Titanium appcelerator合金传递参数

Titanium appcelerator合金传递参数,titanium,appcelerator,titanium-mobile,Titanium,Appcelerator,Titanium Mobile,我试图弄清楚如何在alloy中传递视图之间的争论。我将有一个导航组,它将有多个表,所以它可能有3至5级深 我可以将参数从控制器传递到视图,但我希望在单击下一个表时将信息(类别ID)从视图传递到下一个表 我不知道如何在alloy中实现这一点,在尝试访问变量时,总是会出现未定义的错误。下面是我当前的设置 在我的视图中有:index.xml、master.xml、row.xml、detail.xml、subDetail.xml Index.xml <Alloy> <Wind

我试图弄清楚如何在alloy中传递视图之间的争论。我将有一个导航组,它将有多个表,所以它可能有3至5级深

我可以将参数从控制器传递到视图,但我希望在单击下一个表时将信息(类别ID)从视图传递到下一个表

我不知道如何在alloy中实现这一点,在尝试访问变量时,总是会出现未定义的错误。下面是我当前的设置

在我的视图中有:index.xml、master.xml、row.xml、detail.xml、subDetail.xml

Index.xml

<Alloy>

    <Window id="index">
        <NavigationGroup id="navgroup">
            <Require src="master" id="master"/>
        </NavigationGroup>
    </Window>


</Alloy>
<Alloy>

    <Window title="Categories">
        <TableView id="table" onClick="openDetail">


        </TableView>
    </Window>


</Alloy>
<Alloy>
<TableViewRow>
<Label id="name"/>
<Label id="catID"/>
</TableViewRow>
</Alloy>
    <Alloy>

<Window title="Sub Categories">
<TableView id="subtable" onClick="openSubDetail">
</TableView>

</Window>
</Alloy>
master.xml

<Alloy>

    <Window id="index">
        <NavigationGroup id="navgroup">
            <Require src="master" id="master"/>
        </NavigationGroup>
    </Window>


</Alloy>
<Alloy>

    <Window title="Categories">
        <TableView id="table" onClick="openDetail">


        </TableView>
    </Window>


</Alloy>
<Alloy>
<TableViewRow>
<Label id="name"/>
<Label id="catID"/>
</TableViewRow>
</Alloy>
    <Alloy>

<Window title="Sub Categories">
<TableView id="subtable" onClick="openSubDetail">
</TableView>

</Window>
</Alloy>
detail.xml

<Alloy>

    <Window id="index">
        <NavigationGroup id="navgroup">
            <Require src="master" id="master"/>
        </NavigationGroup>
    </Window>


</Alloy>
<Alloy>

    <Window title="Categories">
        <TableView id="table" onClick="openDetail">


        </TableView>
    </Window>


</Alloy>
<Alloy>
<TableViewRow>
<Label id="name"/>
<Label id="catID"/>
</TableViewRow>
</Alloy>
    <Alloy>

<Window title="Sub Categories">
<TableView id="subtable" onClick="openSubDetail">
</TableView>

</Window>
</Alloy>

detail.js

Alloy.Globals.navgroup = $.navgroup;    


$.master.on('detail', function(e) {
    // get the detail controller and window references
    var controller = Alloy.createController('detail');
    var win = controller.getView();



    // open the detail windows 
    $.navgroup.open(win);
    /*
    if (OS_IOS && Alloy.isHandheld) {
        Alloy.Globals.navgroup.open(win);   
    } else if (OS_ANDROID) {
        win.open();
    }*/
});




$.index.open();
function openDetail(e) {
$.trigger('detail', e);
}


var data = [];

var sendit = Ti.Network.createHTTPClient({ 

                     onerror: function(e){ 

                           Ti.API.debug(e.error); 

                           alert('There was an error during the connection'); 

                     }, 

                  timeout:1000, 

              });                      

              //Here you have to change it for your local ip 


              sendit.open('GET', 'http://url.com/json.php?showCats=1');

              sendit.send(); 

              //Function to be called upon a successful response 

              sendit.onload = function(){ 

                     var json = JSON.parse(this.responseText); 

                     //var json = json.todo; 

                     //if the database is empty show an alert 

                     if(json.length == 0){ 
                        $.table.headerTitle = "The database row is empty"; 
                     }                      

                     //Emptying the data to refresh the view 



                     //Insert the JSON data to the table view


                    for ( var i=0; i<json.length; i++){ 


                        data.push(Alloy.createController('row', {                           
                            name: json[i].CatName,
                            catID: json[i].CatID

                        }).getView());

                        //data.push(row);

                        Ti.API.info(json[i].CatName);
                        Ti.API.info(json[i].CatID);


                    }                                     

                    $.table.setData(data);                      
               }; 
var args = arguments[0] || {};


$.row.fighterName = $.name.text = args.name;
$.catID.text = args.catID;
function openSubDetail(e) {
$.trigger('subDetail', e);


}


var data = [];



var sendit = Ti.Network.createHTTPClient({ 

                     onerror: function(e){ 

                           Ti.API.debug(e.error); 

                           alert('There was an error during the connection'); 

                     }, 

                  timeout:1000, 

              });                      

              //Here you have to change it for your local ip 



              Ti.API.info('Cat id');
              Ti.API.info(catID);
              Ti.API.info('data Value:'+ $.detail.catID );


              sendit.open('GET', 'http://url.com/mobile/includes/json.php?catID=12');

              sendit.send(); 

              //Function to be called upon a successful response 

              sendit.onload = function(){ 

                     var json = JSON.parse(this.responseText); 

                     //var json = json.todo; 

                     //if the database is empty show an alert 

                     if(json.length == 0){ 
                        $.table.headerTitle = "The database row is empty"; 
                     }                      

                     //Emptying the data to refresh the view 



                     //Insert the JSON data to the table view


                    for ( var i=0; i<json.length; i++){ 


                        data.push(Alloy.createController('subDetail', {                         
                            name: json[i].SubcatName,
                            catID: json[i].CatID

                        }).getView());

                        //data.push(row);
                        Ti.API.info('Second Level');
                        Ti.API.info(json[i].SubcatName);

                    }                                     

                    $.subtable.setData(data);                      
               }; 
函数openSubDetail(e){
$.trigger('子细节',e);
}
var数据=[];
var sendit=Ti.Network.createHTTPClient({
onerror:函数(e){
Ti.API.debug(即错误);
警报(“连接过程中出现错误”);
}, 
超时:1000,
});                      
//在这里,您必须为您的本地ip更改它
Ti.API.info(“类别id”);
Ti.API.info(catID);
Ti.API.info('数据值:'+$.detail.catID);
sendit.open('GET','http://url.com/mobile/includes/json.php?catID=12');
sendit.send();
//成功响应时要调用的函数
sendit.onload=函数(){
var json=json.parse(this.responseText);
//var json=json.todo;
//如果数据库为空,则显示警报
如果(json.length==0){
$.table.headerTitle=“数据库行为空”;
}                      
//清空数据以刷新视图
//将JSON数据插入表视图

对于(var i=0;i,在行单击事件上创建一个新控制器,并将对象作为参数传递给控制器。这样,当在控制器中打开窗口时,控制器具有数据


这与您在创建
子详细信息
行时所做的相同

我看不到要将数据传递到哪里的存根代码?我假设您要跟踪某行上的单击事件,然后打开一个新窗口将信息传递到哪里?很抱歉,我不确定要将其传递到哪里。我想从一行传递到另一行详细信息,但我不确定e如何通过它。我尝试了参数0,但它似乎不起作用。我也尝试了查看逃犯,但没有看到它是如何通过的。任何想法都很感激。感谢您的回复。我尝试过,当我这样做时,我会得到“子细节”未定义。我仍然收到一个错误,但我知道你建议的方式是正确的。我尝试将所有details.js移到row.js中。这是你的想法还是有更好的方法?你需要在摘要中发布你的代码,以便有人可以查看你的问题。我在这里创建了摘要。我获取details.js代码并输入row.js但是我可以设置$.subtable.setData,它是未定义的…有什么想法吗?$.subtable怎么可能存在?