[英]Bootstrap popover doesn't work in object
I am trying to make my own js class for table grid adjustments(hide columns) and my popover button doesn't work. 我正在尝试制作自己的js类以进行表格网格调整(隐藏列),而我的弹出按钮不起作用。
When i use all of that functions on page it works, but when I put in prototype it fails. 当我在页面上使用所有这些功能时,它将起作用,但是当我放入原型时,它将失败。
here is my grid.js : 这是我的grid.js :
function Grid(element, tableId, module){
return this.init(element, tableId, module);
};
Grid.prototype = {
grid: [],
element: "",
popover: null,
tableId: "",
module: "",
backEndURL: location.href,
formId: "#grid_form",
wrapper: "#grid_entities",
init: function(element, tableId, module){
this.element = element;
this.tableId = tableId;
this.module = module;
this.initButton();
this.addOnClickListner();
},
initButton: function(){
this.popover = $(this.element).popover({
placement: "bottom",
html: true,
content: this.getPopoverContent()
});
},
...
Index.php: index.php文件:
<div id="filterButtons">
<i class="left iconfilter" id="filterButton" data-toggle="popover"></i>
<i class="left iconlayout" id="gridButton" data-toggle="popover"></i>
</div>
...
<script>
$(document).ready(function () {
var grid = new Grid(...);
});
</script>
Also Grid.js is included in the bottom of the page. 页面底部还包含Grid.js。
I don't see your addOnClickListener but I suspect it's a problem with this
. 我没有看到你的addOnClickListener,但我怀疑这是一个问题this
。 Your constructor function should not return anything. 您的构造函数不应返回任何内容。 So you can do something like this: 因此,您可以执行以下操作:
function Grid(element, tableId, module){
this.init(element, tableId, module);
};
Grid.prototype = {
//...
constructor:Grid,
addOnClickListner:function(){
var me = this;
return function(e){
//e is the event, e.target is the clicked element
//me is the Grid instance
console.log("button clicked, e is:",e," and this is:"
,this," and me is:",me);
me.whateverYouHaveInOnClickListener();
}
}
Errors would be helpful, in Chrome or Firefox (with Firebug plugin installed) press F12 and see if there are any errors in the console. 错误可能会有帮助,在Chrome或Firefox(安装了Firebug插件)中,按F12键,查看控制台中是否有任何错误。 Do a console.log to see what the values of your variables are. 执行console.log以查看变量的值。
More on prototype, constructor functions and the value of this
can be found here . 更多关于原型,构造函数和值this
可以找到这里 。
Thanks to all. 谢谢大家。 I solve it. 我解决了。 The reason was that I generate popover content via ajax: 原因是我通过ajax生成了popover内容:
initButton: function(){
this.popover = $(this.element).popover({
placement: "bottom",
html: true,
trigger: 'click',
content: this.popoverContent
});
},
popoverContent() was a ajax request to server side. popoverContent()是对服务器端的ajax请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.