javascript - js函数的占位符变量

标签 javascript jquery quill

我在一个页面上实例化了四个版本的 quill。现在我想得到每个的内容。是否可以创建一个函数,通过发送名称来识别我所指的 Quill 的实例化版本。

$.fn.getQuillContent = function(instantiatedquill)
    {
    var content =
        {
        text: instantiatedquill.getContents(),
        };
    };

最佳答案

基本上,创建一个处理程序来实例化您的 Quill 并存储它们的实例以供以后重用

class QuillHandler {
  constructor () {
    // this private var would map all different Quill instances through the page
    this._instances = {}
  },

  instanciate (id, node, options) {
    // if trying to instanciate already instanciated Quill instance, return it (or throw an Error?)
    if (this._instances[id]) {
      return this._instances[id]
    }
  }

  // would return undefined if do not exist, otherwithe Quill instance
  get (id) {
    return this._instances[id]
  }
}

在您的文件中,使用全新的处理程序实例化您的 Quills,并通过您用于创建它的 ID 检索每个实例

const handler = new QuillHandler

handler.instanciate('quill1', node, {})
handler.instanciate('quill2', node, {})
handler.instanciate('quill3', node, {})
handler.instanciate('quill4', node, {})

// get quill 4 contents
handler.get('quill4').getContents()

关于javascript - js函数的占位符变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50426965/

相关文章:

javascript - 2.0.0-dev 鹅毛笔拖动文本不起作用如何让它拖动文本

quill - 将 Quill Delta 转换为 HTML

jquery - 在 jQuery 中委托(delegate)就绪事件

jquery - 如何围绕圆形图像对齐按钮

javascript - 我如何在 javascript 中读取对象文件列表数组?

ruby-on-rails - 我一直在尝试通过 Webpack 将 Quilljs 添加到 Rails 5.1 应用程序

javascript - 跨浏览器窗口事件?

javascript - 使用 super 测试传递请求正文以发布

javascript - Node.js 如何获取上一个 url

javascript - 每次页面刷新后事件监听器都会复合