簡體   English   中英

jquery / jquery移動插件-小部件-調用私有方法不起作用

[英]jquery/jquery mobile plugin - widget - calling private method doesn't work

我正在嘗試從我的插件中調用私有方法_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);

您正在嘗試使用錯誤的語法訪問私有方法-使用$page.method試圖將其作為公共方法來調用。

將其更改為this._scrollMe應該可以。

我不認為您在該事件回調中會使用“ this”。

嘗試將$ page變量移到函數外。

var $page = $(this);
$('div[data-role="page"]').live('pagebeforeshow.scroll', function(event){

也許這樣:

var $page = this;

//編輯//

_morph: function() {
    var page = this;
    $('div[data-role="page"]').live('pagebeforeshow.scroll', function(event) {
        if($page.data('scrollable', 'Off') ) {
            $page._scrollMe(); // this doesn't fire 
        }
     });
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM