[英]Array elements are correct in console logs but not rendered correct
I am trying to separate components into arrays of selected, and not selected, in order to campare the former ones.我试图将组件分成选定的和未选定的数组,以便对前者进行标记。 But when the first item of the array is selected, it is copied, instead of added, to the other array - at least on the screen. But when the first item of the array is selected, it is copied, instead of added, to the other array - at least on the screen. But in the console log, the arrays are as they should be.但是在控制台日志中,数组是它们应该的样子。
I found this error when while debugging, but i don't know how to solve this problem.我在调试时发现了这个错误,但我不知道如何解决这个问题。
Exception: Error: : Props cannot be read directly from the component instance unless compiling with 'accessors: true' or '' at Cards.get data [as data] at Cards.invokeGetter (:1:142) at flush异常:错误::除非在 Cards.invokeGetter (:1:142) at 刷新时使用 'accessors: true' 或 '' at Cards.get data [as data] 编译,否则无法直接从组件实例读取道具
this is the repl of the problem 这是问题的repl
<section class="_residencial_cards">
{#if compareList.length > 0}
<div class="test">
<h1>comparar</h1>
{#each compareList as item}
<Card card={item} on:mark={changeList(item)}/>
{/each}
</div>
{/if}
{#each initialCards.filter(c => c.compare === false) as card}
<Card {card} on:mark={changeList(card)}/>
{/each}
</section>
This is the function to divide into arrays :这是划分数组的函数:
function changeList(card) {
compareList = [...compareList, card]
card.compare = true
initialCards = initialCards.filter(t => t !== card)
}
The component card:组件卡:
<label for="{frontprops.name}">Compare</label>
<input type="checkbox" id='{frontprops.name}' name="" on:change={change} >
And its dispach code:及其调度代码:
function change(event) {
check = event.target.checked
dispatch('mark', {
bool: check
})
}
This is the console.log:这是 console.log:
The problem was the key in the each loop:问题是每个循环中的关键:
{#each initialCards.filter(c => c.compare === false) as card}
<Card {card} on:mark={changeList(card)}/>
{/each}
It should be:它应该是:
{#each initialCards.filter(c => c.compare === false) as card,i (card.compare)}
<Card {card} on:mark={changeList(card.compare)}/>
{/each}
and then alter the function accordingly.然后相应地更改功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.