2016-07-02 4 views
0

私は以下のようなコードを持っていますが、エラーはinstance.content()行からです。すべてのコンテンツを動的にロードし、すべてのhrefタグに対して以下のように実行しています。 エラーが キャッチされない例外TypeErrorです:instance.contentは)私はこのjQueryプラグインajax呼び出しのためにツールチップがエラーを返す

ex.find("a[href]").each(function (idx, el) { 
var el = $(el); 
var url = el.prop("href").substring(4); 
el.attr("href", ""); 
el.addClass("popuplink"); 

el.tooltipster({ 
    content: 'Loading...', 
    // 'instance' is basically the tooltip. More details in the "Object-oriented Tooltipster" section. 
    functionBefore: function (instance, helper) { 

     var $origin = $(helper.origin); 

     // we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens 
     if ($origin.data('loaded') !== true) { 

      $.get(url, function (data) { 

      // call the 'content' method to update the content of our tooltip with the returned data 
      instance.content(data); 

      // to remember that the data has been loaded 
      $origin.data('loaded', true); 
      }); 
     } 
    } 

}); 

}を修正することができますどのように機能 ではありません。

答えて

1

Tooltipster v4のファイルを使用していることを確認してください。私があなたに与えたコードではうまくいかない理由は他にありません。

+0

はい。バージョン4.0.4へのアップグレードが機能しました。ありがとうございました。 –

0

誰がV3で、この問題を持つと、これはV3としませV4のために働くしたいされている場合は、あなたがここに古いドキュメントを参照してくださいすることができます

https://web.archive.org/web/20140404021936/http://iamceege.github.io/tooltipster#advanced

基本的に彼らは本当に機能の間働いていた方法を変更それは混乱しています。この作業のV3の例は次のようになります。

$('.tooltip').tooltipster({ 
 
    content: 'Loading...', 
 
    functionBefore: function(origin, continueTooltip) { 
 

 
     // we'll make this function asynchronous and allow the tooltip to go ahead and show the loading notification while fetching our data 
 
     continueTooltip(); 
 
     
 
     // next, we want to check if our data has already been cached 
 
     if (origin.data('ajax') !== 'cached') { 
 
      $.ajax({ 
 
       type: 'POST', 
 
       url: 'example.php', 
 
       success: function(data) { 
 
        // update our tooltip content with our returned data and cache it 
 
        origin.tooltipster('content', data).data('ajax', 'cached'); 
 
       } 
 
      }); 
 
     } 
 
    } 
 
});

関連する問題