从YUI2迁移到YUI3并准备就绪 [英] Migrating from YUI2 to YUI3 and domready
问题描述
我想将站点中的javascript从YU2迁移到YUI3,但是我只是一个可怜的业余程序员,所以我陷入了第一个陷阱.
I want to migrate the javascript in my site from YU2 to YUI3, but I am only a poor amateur programer and I am stuck at the first pitfall.
我有以下代码:
MyApp.Core = function() {
return {
init: function(e, MyAppConfig) {
if (MyAppConfig.tabpanels) {
MyApp.Core.prepareTabpanels(MyAppConfig.tabpanels);
}
},
prepareTabpanels: function(tabpanels) {
// Code here
}
}
}();
var MyAppConfig = {
"tabpanels":{"ids":["navigation"]}
};
YAHOO.util.Event.addListener(window, "load", MyApp.Core.init, MyAppConfig);
如何使用YUI3"domready"事件侦听器将MyAppConfig
对象传递给MyApp.Core.init
函数?
How can I pass the MyAppConfig
object to the MyApp.Core.init
function by using YUI3 "domready" event listener?
提前谢谢!
推荐答案
您应该可以执行以下操作:
You should be able to do something like:
var MyApp = {};
MyApp.Core = function(){ return {
init: function(MyAppConfig) {
console.log(MyAppConfig);
},
prepareTabpanels: function(tabpanels) {
// Code here
}
}
}();
var MyAppConfig = {
"tabpanels":{"ids":["navigation"]}
};
YUI().use('node', 'event', function(Y){
Y.on('domready', MyApp.Core.init, this, MyAppConfig);
});
请注意,事件不是作为第一个参数传递的,它是配置.
Note that the event is not passed in as the first parameter, it is the config.
Y.on接受的参数为<event_type>
,<callback_function>
,<context>
,<params>
..
Y.on accepts parameters as <event_type>
, <callback_function>
, <context>
, <params>
..
将第三项之后的任何参数传递给回调函数,以便MyAppConfig成为init中的第一个参数.
any parameter after the third item is passed through to the callback function so MyAppConfig becomes the first parameter in your init.
编辑 请参阅此处的YUI3 API文档: http://developer.yahoo.com/yui/3/api/YUI.html#method_on
EDIT See the YUI3 API documentation here: http://developer.yahoo.com/yui/3/api/YUI.html#method_on
这篇关于从YUI2迁移到YUI3并准备就绪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!