jquery/jquery 移动插件 - 小部件 - 调用私有方法不起作用
我试图从我的插件中调用私有方法 _scrollMe,但我不断收到错误消息,表明它不是函数。
有人可以告诉我我做错了什么吗?谢谢!
(function( $, window, undefined ){ $.widget( "mobile.multiview", $.mobile.widget, { _create: function() { this._morph(); }, _morph: function() { $('div[data-role="page"]').live('pagebeforeshow.scroll', function(event){ var $page = $(this); if ( $page.data('scrollable', 'Off') ) { $page._scrollMe(); // this doesn't fire } }); }, _scrollMe: function () { alert ("scrollMe"); } }); // initialize $( document ).bind( "pagecreate", function( ) { $(document).multiview(); }); })(jQuery,window);
I'm trying to call the private method _scrollMe from within my plugin, but I keep getting an error that it's not a function.
Can somebody tell me what I'm doing wrong? Thanks!
(function( $, window, undefined ){ $.widget( "mobile.multiview", $.mobile.widget, { _create: function() { this._morph(); }, _morph: function() { $('div[data-role="page"]').live('pagebeforeshow.scroll', function(event){ var $page = $(this); if ( $page.data('scrollable', 'Off') ) { $page._scrollMe(); // this doesn't fire } }); }, _scrollMe: function () { alert ("scrollMe"); } }); // initialize $( document ).bind( "pagecreate", function( ) { $(document).multiview(); }); })(jQuery,window);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您试图使用错误的语法访问私有方法 - 使用
$page.method
试图将其作为公共方法调用。将其更改为
this._scrollMe
应该可以。You're trying to access the private method using the wrong syntax - using
$page.method
is trying to call it as a public method.Changing it to
this._scrollMe
should work.我认为“这”不是您期望的事件回调中的内容。
尝试将 $page 变量移到函数之外。
也许可以这样:
// 编辑 //
I don't think 'this' is what you expect it to be in that event callback.
Try moving the $page variable outside the function.
and maybe this instead:
// Edit //