4

合金のビュー間で引数を渡す方法を理解しようとしています。複数のテーブルを持つ have nav グループを作成するので、おそらく 3 ~ 5 レベルの深さになります。

コントローラーからビューに引数を渡すことはできますが、クリックされたときにビューから次のテーブルに情報 (カテゴリの ID) を渡したいと考えています。

合金でこれを行う方法がわかりません。変数にアクセスしようとすると、常に未定義のエラーが発生します。以下は私の現在の設定です。

私の見解では、index.xml、master.xml、row.xml、detail.xml、subDetail.xml があります。

索引.xml

<Alloy>

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


</Alloy>

これが私のindex.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();

master.xml

<Alloy>

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


        </TableView>
    </Window>


</Alloy>

master.js

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

行.xml

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

行.js

var args = arguments[0] || {};


$.row.fighterName = $.name.text = args.name;
$.catID.text = args.catID;

詳細.xml

    <Alloy>

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

</Window>
</Alloy>

詳細.js

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

1 に答える 1

2

行クリック イベントで新しいコントローラーを作成し、オブジェクトをパラメーターとしてコントローラーに渡します。このようにして、コントローラーでウィンドウが開かれると、コントローラーにはデータがあります。

subDetail行を作成したときと同じです

于 2013-06-17T02:22:54.587 に答える