簡體   English   中英

迭代時TypeScript中的JQuery-elements數組類型錯誤

[英]Array of JQuery-elements in TypeScript has wrong type when iterating

在我的TypeScript類中,我有一個JQuery元素數組,可以通過調用來填充

this.$elements = $sourceElement.find(`[data-filter-element]`).toArray();

$elements : JQuery[]; 是這樣定義的。

問題是當我嘗試遍歷這些元素時:

this.$elements.forEach((current) => {
    var $current = $(current); // <-- why do I have to do this?
    // ...
});

為什么這里的current類型不正確( JQuery )?

我也嘗試使用

for(let current of this.$elements){
    // same issue here
}

以及

$.each(this.$elements, (idx, current) => {
    // same issue here
});

jQuery對象根據定義表示DOM元素列表。

它們不代表更多 jQuery對象的列表。

真的,這就是所有要說的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM