扩展bootstrap select插件 [英] Extend bootstrap select plugin

查看:57
本文介绍了扩展bootstrap select插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我之前的问题中,我在讨论bootstrap select插件,其中destroy方法正在做我不想要的事情。我手动编辑插件,但这不是一个好习惯。

In my previous question I was talking about the bootstrap select plugin where the destroy method is doing something that I don't want. I edit manually the plugin but this is not a good practice.

Bootstrap select destroy从DOM中删除原始选择

我想用自定义方法扩展插件,以便它可以完全按照我想要的方式执行。

I would like to extend the plugin with a custom method so that it can do exactly wat I want.

我使用以下方法扩展插件:

I extend the plugin with folloing method:

$.extend(true, $.fn.selectpicker.prototype, {
    customRemove: function () {
        this.$newElement.remove();
        this.$element.show();
    }
});

这位于bootstrap select脚本文件下的另一个js文件中。

This is located in another js file under the bootstrap select script file.

如何调用这种新方法?我尝试了以下但没有成功:

How do I call this new method? I tried the following without success:

$('select#begin' + _week + _day).selectpicker("customRemove");

$('select#begin' + _week + _day).selectpicker().customRemove();

我错过了什么吗?

bootstrap select插件中destroy函数的原始方法:

The original method of the destroy function in the bootstrap select plugin:

remove: function () {
  this.$newElement.remove();
  this.$element.show();
}


推荐答案

我想,你有其他问题的正确答案:

https://stackoverflow.com/a/31852632/4928642

I think, you have the correct answer in other your question:
https://stackoverflow.com/a/31852632/4928642

jQuery.fn.selectpicker.Constructor.prototype.customRemove = function () {
  this.$newElement.remove();
  this.$element.show();
};

然后

$smth.selectpicker("customRemove");

这篇关于扩展bootstrap select插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆