aynı sorunu ederiz, kodu, kapsamlı ve sadece bir exemple, optimize!
// functions container
var doc =
{
doPopover : function(item_id, title, content)
{
// get jq item
var item = $('#' + item_id);
// the trick to "refresh content" in every call
item.attr('data-content', content);
// popover
item.popover(
{
title : title,
trigger : 'manual'
}).popover('show');
},
popoverFirstCall : function()
{
this.doPopover('myDiv', 'Title', 'MyContent1');
},
popoverSecondCall : function()
{
var content = 'xxx'; // get the content in Ajax
this.doPopover('myDiv', 'Title', content);
}
}
// call funcs in your views
$(document).ready(function()
{
// first popover with first content
doc.popoverFirstCall();
// this event wich call the ajax content and refresh popover.
$('#button').on('click', $.proxy(doc, 'popoverSecondCall'));
});
Ayrıca, hile de başlığı yenilemek için aynı olduğunu varsayalım.
Daha iyi bir çözümün varsa, plz söyle!
DÜZENLEME: soruşturması devam
,
biz eklenti koduna görebilirsiniz
:
getContent: function() {
var content
, $e = this.$element
, o = this.options
content = $e.attr('data-content')
|| (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
return content
}
yüzden, içerik attr "veri-içerik" alınır ya verilen seçeneklere popletin ilk çağrısı (instanciation).
Ama aslında, probleme olan, seçenekler yüzden wa kullanmak zorunda önbelleğe ve her çağrıda yenilemek değildir:
$('item_id').attr('data-content', 'some content'); // and warning, it is different than
$('item_id').data('content', 'some content');
Ve attr yol almak Bootstrap. başlık için aynı
:
getTitle: function() {
var title
, $e = this.$element
, o = this.options
title = $e.attr('data-original-title')
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
return title
}
Yani, doPopover fonksiyonu olabilir: Benim için
doPopover : function(item_id, title, content)
{
// get jq item
var item = $('#' + item_id);
// the trick to "refresh content" in every call
item.attr('data-content', content); // do not use data() way.
item.attr('data-original-title', title);
// popover (trace first call if you want)
item.popover(
{
trigger : 'manual'
});
item.popover('show);
}
Çalışma cezası. Bunun yerine data-content
özelliğini sıfırlama
item.attr ('veri içeriği', içerik); Eserleri! Teşekkürler! Bootstrap v2.0.4 kullanımı – Dean