简体   繁体   English

控制台日志中的数组元素是正确的,但未呈现正确

[英]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.

相关问题 Angular JS控制台记录正确但没有输出 - Angular JS console logs correct but no output 为什么这个 function 返回 undefined 但 console.logs 正确答案? - Why does this function return undefined but console.logs the correct answer? JavaScript 返回数组长度为 0,但控制台中的长度正确 - JavaScript returning array length of 0, but correct length in console Momentjs显示isValid为true,并且控制台记录正确的日期,并闪烁正确的.fromNow(),但很快变为无效日期 - Momentjs shows isValid true and console logs correct date and flashed correct .fromNow() but quickly changes to invalid date JavaScript:如何检查数组中的元素长度是否正确 - JavaScript: how to check if elements in array are the correct length 数组在控制台中记录为对象的填充数组,但单个元素未定义 - Array logs in the console as a pupulated array of objects but individual elements as undefined Firebase数据库调用中的数组记录正确的数据,但长度显示为0 - Array from firebase database call logs correct data but length shows 0 在 JS 数组中显示出现,在控制台中返回正确但在 HTML 上未定义? - Showing occurences in JS array, returns correct in console but undefined on HTML? 数组值在 DOM 中没有变化,但在 console.log 中显示正确 - array values do not change in DOM, but shows correct in in console.log 正确的控制台输出后,Javascript数组变得未定义 - Javascript array becomes undefined right after correct console output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM