gpt4 book ai didi

javascript - js函数的占位符变量

转载 作者:行者123 更新时间:2023-12-05 07:33:45 25 4
gpt4 key购买 nike

我在一个页面上实例化了四个版本的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com