【发布时间】:2022-03-01 04:56:18
【问题描述】:
你能帮忙吗?
我正在尝试根据循环中的某些属性添加倒计时,但我找不到任何方法(不是通过尝试也不是通过谷歌搜索)如何在我的函数中传递该值:
<template x-for="item in cartData.items">
[...]
<template x-if="item.product_type == 'test'">
<div x-data="getCountdown()" x-init="init()">
<span x-text="timeLeft(item.timerEnd)"></span>
</div>
<script type="text/javascript">[...]
</script>
</template>
</template>
我试图将 item.timerEnd 传递给每个函数(getCountdown、init 和 timeLeft),但我总是收到 item 未定义的错误,如果我传递它,例如。至
<span x-text="new Date(item.timerEnd).toLocaleString()"></span> 这行得通。
我错过了什么?
PS:感谢fpr在这里的第一个帮助:How to make timer in alpine.js app with time interval
【问题讨论】:
-
x-for必须只有一个根元素,根据 this doc。
标签: alpine.js