[英]how to pass parameters to popover content function of bootstrap
I want to add conditions as to what type of text should be shown in popovers.我想添加关于应该在弹出窗口中显示什么类型的文本的条件。 So I wrote the function:
所以我写了这个函数:
var initErrorPopOverEvent = function(hasRequiredError,option){
if(hasRequiredError !== undefined && hasRequiredError === true){
$(".icon-warning-lg").popover({
html:true,
placement:'top',
'trigger': 'hover ',
content:function(){
return $("#required-field-error").text();
}
});
}
if(option !== undefined){
if(option === "option1"||option === "option2"){
$("#opt1-warning").popover({
html:true,
placement:'top',
'trigger': 'hover ',
content:function(){
return $("#opt1-error").text();
}
});
}
if(option === "option3" || option === "option2"){
$("#opt2-warning").popover({
html:true,
placement:'top',
'trigger': 'hover ',
content:function(){
return $("#opt2-error").text();
}
});
}
}
}
But I want all these conditions to go inside the function which displays popover content.但我希望所有这些条件都包含在显示弹出框内容的函数中。 something like:
就像是:
content:function(hasRequiredError,option){//render text according to condition
}
How do I do this?我该怎么做呢?
You should pass it a map in Javascript.您应该在 Javascript 中将地图传递给它。 {key:value}
{核心价值}
Try this:尝试这个:
var hasRequiredError = ...;
var option = ...;
var options = {'content':initErrorPopOverEvent(hasRequiredError,option)};
$('#myElement').popover( options );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.