将参数传递给appcelerator中的另一个控制器

时间:2021-06-18 19:42:17

I am trying to implement a list view in Appcelerator. On the click event of a list item, a new controller should appear and according to the item index and the URL mentioned in the list item, the video should auto play in the new controller. Every list item has a different URL that should play on the click event of that list item. I have implemented the list view and am unable to figure out how to pass the argument e of the call back function to another controller, for it to recognize it and play the appropriate video.

我正在尝试在Appcelerator中实现列表视图。在列表项的单击事件上,应该出现一个新的控制器,并根据项目索引和列表项中提到的URL,视频应该在新控制器中自动播放。每个列表项都有一个不同的URL,应该在该列表项的click事件上播放。我已经实现了列表视图,我无法弄清楚如何将回调函数的参数e传递给另一个控制器,以便识别它并播放相应的视频。

1 个解决方案

#1


0  

I do not yet understand your whole usecase, but usually you pass arguments to a new Controller via a dictionary in the Constructor:

我还不了解你的整个用例,但通常你会通过构造函数中的字典将参数传递给新的Controller:

index.js

var myCtrl = Alloy.createController("MyController", {
    //put your arguments here
});

You can recieve the args in the created controller by using $.args

您可以使用$ .args在创建的控制器中接收args

if you create the Controller via require in the XML you have to call a setter.

如果您通过XML中的require创建Controller,则必须调用setter。

index.xml

<Alloy>
   <require src="MyController" id="myCtrl"/>
</Alloy>

index.js

$.myCtrl.setArgs({
    //put your arguments here
})

MyController.js

$.setArgs = function(args){
    //handleNewArgs
}

#1


0  

I do not yet understand your whole usecase, but usually you pass arguments to a new Controller via a dictionary in the Constructor:

我还不了解你的整个用例,但通常你会通过构造函数中的字典将参数传递给新的Controller:

index.js

var myCtrl = Alloy.createController("MyController", {
    //put your arguments here
});

You can recieve the args in the created controller by using $.args

您可以使用$ .args在创建的控制器中接收args

if you create the Controller via require in the XML you have to call a setter.

如果您通过XML中的require创建Controller,则必须调用setter。

index.xml

<Alloy>
   <require src="MyController" id="myCtrl"/>
</Alloy>

index.js

$.myCtrl.setArgs({
    //put your arguments here
})

MyController.js

$.setArgs = function(args){
    //handleNewArgs
}