Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Aurelia.js在单击后插入CSS类并仅绑定单击的行_Javascript_Aurelia - Fatal编程技术网

Javascript Aurelia.js在单击后插入CSS类并仅绑定单击的行

Javascript Aurelia.js在单击后插入CSS类并仅绑定单击的行,javascript,aurelia,Javascript,Aurelia,我的代码正在运行,但我有一个bug,因为重复。对于所有td更改颜色,实际上我只想更改1行更改颜色,即我单击的行 有人知道如何在奥雷利亚解决这个问题 谢谢 js: css: html: ${day | dateFormat:'M/D/YYYY'} ${time} ${location} 如果isSelected是$items中每个项目的属性,changeColor()是$items中每个项目的函数,那么您需要像这样调用函数juice.changeColor(),并且需要在class属性中使用ju

我的代码正在运行,但我有一个bug,因为
重复。对于
所有td更改颜色,实际上我只想更改1行更改颜色,即我单击的行

有人知道如何在奥雷利亚解决这个问题

谢谢

js:

css:

html:


${day | dateFormat:'M/D/YYYY'}
${time}
${location}

如果
isSelected
$items
中每个项目的属性,
changeColor()
$items
中每个项目的函数,那么您需要像这样调用函数
juice.changeColor()
,并且需要在class属性中使用
juice.isSelected
。此外,您需要在表中列出的所有属性之前使用
juice.
,例如
${juice.location}

您需要更改视图,使其如下所示:

<table>
  <tr repeat.for="juice of $items" class="${juice.isSelected ? 'is-row-selected' : 'is-row-not-selected'}" click.trigger="juice.changeColor()">
   <td>${juice.day | dateFormat: 'M/D/YYYY'}</td>
   <td>${juice.time}</td>
   <td>${juice.location}</td>
  </tr>
</table>
以及您的模板:

<table>
  <tr repeat.for="juice of $items" class="${juice.isSelected ? 'is-row-selected' : 'is-row-not-selected'}" click.trigger="changeColor(juice)">
   <td>${juice.day | dateFormat: 'M/D/YYYY'}</td>
   <td>${juice.time}</td>
   <td>${juice.location}</td>
  </tr>
</table>

${juice.day |日期格式:'M/D/YYYY'}
${juice.time}
${juice.location}
考虑到您提供的代码,我真的不能说这些答案中哪一个适合您,但它应该是其中之一

<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
    <script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
    <script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
    <script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<table>
  <tr repeat.for="juice of $items" class="${isSelected ? 'is-row-selected' : 'is-row-not-selected'}" click.trigger="changeColor()">
   <td>${day | dateFormat: 'M/D/YYYY'}</td>
   <td>${time}</td>
   <td>${location}</td>
  </tr>
</table>
<table>
  <tr repeat.for="juice of $items" class="${juice.isSelected ? 'is-row-selected' : 'is-row-not-selected'}" click.trigger="juice.changeColor()">
   <td>${juice.day | dateFormat: 'M/D/YYYY'}</td>
   <td>${juice.time}</td>
   <td>${juice.location}</td>
  </tr>
</table>
changeColor(item) {
 alert(item.new);
 item.isSelected = !item.isSelected;
}
<table>
  <tr repeat.for="juice of $items" class="${juice.isSelected ? 'is-row-selected' : 'is-row-not-selected'}" click.trigger="changeColor(juice)">
   <td>${juice.day | dateFormat: 'M/D/YYYY'}</td>
   <td>${juice.time}</td>
   <td>${juice.location}</td>
  </tr>
</table>