当前位置:网站首页>微信小程序 TODO案例
微信小程序 TODO案例
2022-07-24 13:44:00 【林一怂儿】
源于 https://ask.csdn.net/questions/7759861 进行了简化。
效果

代码
index.js
Page({
data: {
// 待办列表
todoList: [
{
thing: '洗衣服',
completed: false
},
{
thing: '刷鞋',
completed: false
},
{
thing: '写代码',
completed: false
}
],
// 待办事务
todoThing: ""
},
// 待办点击
todoClick(e) {
// 从wxml传入的点击的索引
let index = e.currentTarget.dataset.index;
this.setData({
// 通过索引进行更改条目
[`todoList[${
index}].completed`]: !this.data.todoList[index].completed
})
},
// 待办输入
todoThingInput(e) {
this.setData({
todoThing: e.detail.value })
},
// 添加按钮
addClick() {
this.setData({
// 再数组最后追加一条
[`todoList[${
this.data.todoList.length}]`]: {
thing: this.data.todoThing,
completed: false
},
// 新增后清空输入框
todoThing: ''
})
},
// 删除按钮
deleteClick(e) {
// 从wxml传入的点击的索引
let index = e.currentTarget.dataset.index;
// 删除todoList索引为index的条目
this.data.todoList.splice(index, 1)
this.setData({
// 对数组重新赋值
todoList: this.data.todoList
})
}
})
index.wxml
<wxs module="tools">
module.exports.getProgress = function (todo) {
var length = todo.length;
var checked = 0;
for (var i = 0; i < todo.length; i++) {
if (todo[i].completed) {
checked++;
}
}
return '完成度:' + (checked / length * 100).toFixed(2) + '%'
}
</wxs>
<view class="todo-completion">{
{tools.getProgress(todoList)}}</view>
<view class="todo-list">
<view class="todo-item" wx:for="{
{todoList}}" wx:key="unique" bindtap="todoClick" data-index="{
{index}}">
<!-- 点击条目增加删除线 -->
<view class="todo-form-label {
{item.completed?'delete-line':''}}">
<radio checked="{
{item.completed}}" /> {
{item.thing}}
</view>
<!-- catchtap阻止冒泡并绑定事件 -->
<view class="todo-delete" catchtap="deleteClick" data-index="{
{index}}">删除</view>
</view>
</view>
<view class="todo-form">
<!-- bindconfirm 点击完成按钮时触发 -->
<input class="form-item" type="text" placeholder="请输入想要做的事情" value="{
{todoThing}}" bindinput="todoThingInput" bindconfirm="addClick" />
<button type="primary" bindtap="addClick">添加</button>
</view>
index.wxss
.todo-form {
padding: 20rpx 60rpx;
}
.todo-form .form-item {
margin-bottom: 40rpx;
font-size: 36rpx;
}
.todo-item .todo-form-label {
/* 阻止原有组件的事件 */
pointer-events: none;
}
.delete-line {
/* 给文字增加删除线 */
text-decoration: line-through;
color: rgba(0, 0, 0, .5);
}
.todo-list {
padding: 30rpx 60rpx;
display: flex;
/* 通过样式来控制从头部追加 */
flex-direction: column-reverse;
}
.todo-list .todo-item {
margin-bottom: 40rpx;
align-items: center;
display: inline-flex;
font-size: 28rpx;
justify-content: space-between;
}
.todo-item .todo-delete {
line-height: 48rpx;
padding: 0 20rpx;
font-size: 28rpx;
color: #ff0000;
}
.todo-completion{
text-align: center;
padding: 20rpx 0;
}
边栏推荐
- Spelling words~
- Data formatting widget
- Network security - file upload competitive conditions bypass
- 网络安全——报错注入
- Swarm intelligence collaborative obstacle avoidance method inspired by brain attention mechanism
- Statistical table of competition time and host school information of 2022 national vocational college skills competition (the second batch)
- WSDM 22 | 基于双曲几何的图推荐
- 网络安全——Web渗透测试
- Network security - function bypass injection
- R语言使用epiDisplay包的tableStack函数制作统计汇总表格(基于目标变量分组的描述性统计、假设检验等)、设置by参数为目标变量、设置percent参数配置是否显示百分比信息
猜你喜欢

Network security - function bypass injection

网络安全——过滤绕过注入

游戏思考04总结:针对帧、状态、物理同步的总结(之前写的太长,现在简略下)

网络安全——Cookie注入

rhce第一次作业

The scroll bar in unity ugui is not displayed from the top when launching the interface in the game

群体知识图谱:分布式知识迁移与联邦式图谱推理

position: -webkit-sticky; /* for Safari */ position: sticky;

Simulate the implementation of the library function memcpy-- copy memory blocks. Understand memory overlap and accurate replication in detail

【无标题】
随机推荐
22-07-23周总结
R语言使用epiDisplay包的statStack函数基于因子变量通过分层的方式查看连续变量的统计量(均值、中位数等)以及对应的假设检验、对连续数据进行对数化之后符合参数检验条件自动执行参数检验
Game thinking 04 summary: a summary of frame, state and physical synchronization (it was too long before, and now it's brief)
Interface document evolution atlas, some ancient interface document tools, you may not have used them
The scroll bar in unity ugui is not displayed from the top when launching the interface in the game
Is it safe for Huatai Securities to open an account through channels? Is it formal
Odoo+ test
Go redis pipeline application
Wildcard (Pan domain name) SSL certificate
JS execution mechanism
Repair the problem of adding device groups and editing exceptions on easycvr platform
The R language uses the sort function to sort vector data and return the actually sorted data (ascending by default)
Flex layout
Dtcloud uses custom fonts
From cloud native to intelligent, in-depth interpretation of the industry's first "best practice map of live video technology"
JQ remove an element style
通配符(泛域名)SSL证书
网络安全——Web信息收集
Flink综合案例(九)
脑注意力机制启发的群体智能协同避障方法