todoList.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // pages/todoList/todoList.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. inpVal:'',
  8. todoList:[{
  9. id:101,
  10. title: '学习'
  11. },{
  12. id: 102,
  13. title: '吃饭'
  14. },{
  15. id: 103,
  16. title: '睡觉'
  17. }]
  18. },
  19. //添加事件
  20. addTodo(event){
  21. console.log(event)
  22. // console.log(this.data.todoList)
  23. let _id = this.data.todoList[this.data.todoList.length - 1].id + 1
  24. console.log(_id)
  25. let _val = {
  26. id: _id,
  27. title: this.data.inpVal
  28. }
  29. let _todo = this.data.todoList
  30. _todo.push(_val)
  31. this.setData({
  32. todoList: _todo,
  33. inpVal: ""
  34. })
  35. },
  36. //输入框事件
  37. inputValue(event){
  38. console.log(event.detail.value)
  39. this.setData({
  40. inpVal: event.detail.value
  41. })
  42. },
  43. //完成事件
  44. down(event){
  45. console.log(event)
  46. console.log(event.currentTarget.dataset.id)
  47. let _id = event.currentTarget.dataset.id
  48. let _arr = this.data.todoList.filter((val)=>{
  49. if(val.id != _id){
  50. return val
  51. }
  52. })
  53. console.log(_arr)
  54. this.setData({
  55. todoList: _arr
  56. })
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad(options) {
  62. },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady() {
  67. },
  68. /**
  69. * 生命周期函数--监听页面显示
  70. */
  71. onShow() {
  72. },
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide() {
  77. },
  78. /**
  79. * 生命周期函数--监听页面卸载
  80. */
  81. onUnload() {
  82. },
  83. /**
  84. * 页面相关事件处理函数--监听用户下拉动作
  85. */
  86. onPullDownRefresh() {
  87. },
  88. /**
  89. * 页面上拉触底事件的处理函数
  90. */
  91. onReachBottom() {
  92. },
  93. /**
  94. * 用户点击右上角分享
  95. */
  96. onShareAppMessage() {
  97. }
  98. })