[英]WebStorm expecting multiple arguments for $.insertBefore()?
I have the following code which is currently working as desired. 我有以下代码,目前正在按要求工作。 It inserts elements into
objGrid
according to the property loadOrder
. 它插入元素注入
objGrid
根据属性loadOrder
。
let $elTileTitle = $('<div/>', { class: 'tileTitle', html: tile.title });
let $elNext;
for (let i = tile.loadOrder; i < objectLength(tiles); i++) {
let $potentialNext = $(`.tile[data-loadorder="${i}"]`);
if ($potentialNext.length > 0) {
$elNext = $potentialNext;
break;
}
}
if (typeof $elNext !== 'undefined') {
$elTile.insertBefore($elNext);
} else {
let $elPrev;
for (let i = tile.loadOrder; i < 0; i--) {
let $potentialPrev = $(`.tile[data-loadorder="${i}"]`);
if ($potentialPrev.length > 0) {
$elPrev = $potentialPrev;
break;
}
}
if (typeof $elPrev !== 'undefined') {
$elTile.insertAfter($elPrev);
} else {
$elTile.appendTo(objGrid);
}
}
As stated, this seems to work well. 如上所述,这似乎运作良好。 But I noticed a warning in my IDE that
insertBefore()
had an invalid number of arguments. 但是我注意到我的IDE中有一个警告:
insertBefore()
的参数数量无效。 After viewing the documentation, I replaced that line with this: 查看文档后,我用以下内容替换了该行:
$('#grid').insertBefore($elTile,$elNext);
This has presented odd behavior. 这带来了奇怪的行为。 After this code runs,
$('#grid')
is empty. 运行此代码后,
$('#grid')
为空。 Oddly, all the tiles exist in the DOM (ie, if I type $('#tile-store')
in the console, I get an object back with all the expected properties), however I cannot find them in the HTML ("Elements" tab) and the UI is blank. 奇怪的是,所有的磁贴都存在于DOM中(即,如果我在控制台中键入
$('#tile-store')
,我会得到一个带有所有预期属性的对象),但是我无法在HTML中找到它们(“元素“选项卡”和UI是空白的。
Is there something obvious I'm doing wrong? 有什么明显的东西我做错了吗? I can provide more information if needed
如果需要,我可以提供更多信息
But I noticed a warning in my IDE that insertBefore() had an invalid number of arguments.
但是我注意到我的IDE中有一个警告:insertBefore()的参数数量无效。
Your IDE is mistaken. 你的IDE错了。 It's mistakenly applying the rules for the DOM's
insertBefore
to your use of jQuery's insertBefore
. 它错误地将DOM的
insertBefore
的规则应用于你使用jQuery的 insertBefore
。 Your original use of jQuery's is just fine. 你最初使用jQuery就好了。 If you were using the DOM's, you'd need to give it another argument.
如果你使用的是DOM,你需要给它另一个参数。 But they're completely different functions.
但它们的功能完全不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.