위챗 애플릿 - 간편한 정보 관리
//index.js
const app = getApp()
const db = wx.cloud.database()
Page({
  data: {
    username: " ",
    userId: " ",
    result:' ',
    currentId:' '
  },
  onLoad: function() {
  },
  forName: function(e) {
    this.setData({
      username: e.detail.value
    })
    console.log("username", this.data.username)
  },
  forUserId: function(e) {
    this.setData({
      userId: e.detail.value
    })
    console.log("userId", this.data.userId)
  },
  onQuery: function () {
    db.collection('exam-userinfo').where({
      username: this.data.username
    }).get({
      success: res => {
        this.setData({
          result:res.data,
          currentId: res.data[0]._id
        })
        console.log('[ ] [ ]  : ', this.data.result,this.data.currentId)
        wx.showToast({
          title: ' '
        })
        wx: wx.navigateTo({
          url: '/pages/second/second?currentId=' + this.data.currentId + '&username=' + this.data.username + '&userId=' + this.data.userId
        })
        
      },
      fail: err => {
        console.error('[ ] [ ]  :', err)
      }
    })
  },
  onAdd: function () {
    db.collection('exam-userinfo').add({
      data: {
        username: this.data.username,
        userId: this.data.userId
      },
      success: res => {
        wx: wx.showToast({
          title: ' '
        })
        console.log('[ ] [ ]  ,  _id: ', res._id)
      },
      fail: err => {
        console.error('[ ] [ ]  :', err)
      }
    })
  },
  display: function() {
    wx:wx.navigateTo({
      url: '/pages/detail/detail?username=' + this.data.username + '&userId=' + this.data.userId
    })
  }
})
<!-- index.wxml -->
<view class='con'>
  <view class="weui-cells weui-cells_after-title">
    <view class="weui-cell ">
      <view class="weui-cell__hd">
        <view class="weui-label"> </view>
      </view>
      <view class="weui-cell__bd">
        <input class="weui-input" bindinput="forName" placeholder=" " />
      </view>
    </view>
  </view>
  <view class="weui-cells weui-cells_after-title">
    <view class="weui-cell ">
      <view class="weui-cell__hd">
        <view class="weui-label"> </view>
      </view>
      <view class="weui-cell__bd">
        <input class="weui-input" bindinput="forUserId" placeholder=" " />
      </view>
    </view>
  </view>
  <!--   -->
  <view class="button-sp-area btn btn">
    <button class="weui-btn" type="default" bindtap="onAdd"> </button>
    <button class="weui-btn" type="default" bindtap="display"> </button>
    <button class="weui-btn" type="default" bindtap="onQuery"> </button>
  </view>
</view>
/* miniprogram/pages/detail/detail.wxss */
.display {
  display: flex;
  flex-direction: row;
  margin-top: 15px;
  background-color: rgba(27, 223, 86, 0.651);
}
.name {
  margin-left: 10px;
  width: 35%;
}
.id {
  width: 50%;
}
.user {
  display: flex;
  flex-direction: row;
}
.btn {
  margin-top: 10px;
  display: flex;
  flex-direction: row;
}
.btn2 {
  margin-top: 10px;
  background-color: rgba(27, 223, 86, 0.651);
  width: 40%;
}
.btn1 {
  background-color: rgba(179, 241, 198, 0.651);
  width: 40%;
}
// miniprogram/pages/detail/detail.js
Page({
  data: {
    username: ' ',
    userId: ' ',
    queryResult: [],
    currentID: ' '
  },
  onLoad: function(options) {
    const db = wx.cloud.database()
    db.collection('exam-userinfo').get({
      success: res => {
        this.setData({
          queryResult: res.data
        })
        console.log('[ ] [ ]  : ', res)
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: ' '
        })
        console.error('[ ] [ ]  :', err)
      }
    })
  },
  forName: function(e) {
    this.setData({
      username: e.detail.value
    })
    console.log("username", this.data.username)
  },
  forUserId: function(e) {
    this.setData({
      userId: e.detail.value
    })
    console.log("userId", this.data.userId)
  },
  onQuery: function() {
    const db = wx.cloud.database()
    //   counters
    db.collection('exam-userinfo').where({
      username: this.data.username
    }).get({
      success: res => {
        wx.showToast({
          title: ' '
        })
        wx: wx.navigateTo({
          url: '/pages/second/second'
        })
        console.log('[ ] [ ]  : ', res)
      },
      fail: err => {
        console.error('[ ] [ ]  :', err)
      }
    })
  },
  onAdd: function() {
    const db = wx.cloud.database()
    db.collection('exam-userinfo').add({
      data: {
        username: this.data.username,
        userId: this.data.userId
      },
      success: res => {
        wx: wx.showToast({
          title: ' '
        })
        console.log('[ ] [ ]  ,  _id: ', res._id)
      },
      fail: err => {
        console.error('[ ] [ ]  :', err)
      }
    })
  },
})
// miniprogram/pages/second/second.js
const db = wx.cloud.database()
Page({
  data: {
    username: " ",
    userId: " ",
    currentId: ' ',
    result: [ ]
  },
  onLoad: function(options) {
    this.setData({
      currentId: options.currentId,
      username:options.username,
      userId:options.userId
    })
    db.collection('exam-userinfo').where({
      username: this.data.username
    }).get({
      success: res => {
        this.setData({
          result: res.data
        })
        console.log('second[ ] [ ]  : ', this.data.currentId)
        wx.showToast({
          title: ' '
        })
      },
      fail: err => {
        console.error('[ ] [ ]  :', err)
      }
    })
  },
  onUpdate: function () {
    const db = wx.cloud.database()
    db.collection('exam-userinfo').doc(this.data.currentId).update({
      data: {
        userId:this.data.userId
      },
      success: res => {
        // this.setData({
        //   count: newCount
        // })
        wx.showToast({
          title: ' ',
        })
        console.log("update :" ,res.data)
      },
      fail: err => {
        icon: 'none',
          console.error('[ ] [ ]  :', err)
      }
    })
  },
  onDeleta: function () {
    if (this.data.currentId) {
      const db = wx.cloud.database()
      db.collection('exam-userinfo').doc(this.data.currentId).remove({
        success: res => {
          wx.showToast({
            title: ' ',
          })
          console.log("delete :" ,res)
        },
        fail: err => {
          wx.showToast({
            icon: 'none',
            title: ' ',
          })
          console.error('[ ] [ ]  :', err)
        }
      })
    } else {
      wx.showToast({
        title: ' , ',
      })
    }
  }
})
<!--miniprogram/pages/second/second.wxml-->
<view>
  <view wx:for='{{result}}' wx:key='key'>
    <view> :{{item.username}}</view>
    <view> :{{item.userId}}</view>
  </view>
  <button bindtap="onDeleta"> </button>
  <button bindtap="onUpdate"> </button>
</view>
// miniprogram/pages/detail/detail.js
Page({
  data: {
    username: ' ',
    userId: ' ',
    queryResult: [],
    currentID: ' '
  },
  onLoad: function(options) {
    const db = wx.cloud.database()
    db.collection('exam-userinfo').get({
      success: res => {
        this.setData({
          queryResult: res.data
        })
        console.log('[ ] [ ]  : ', res)
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: ' '
        })
        console.error('[ ] [ ]  :', err)
      }
    })
  },
  forName: function(e) {
    this.setData({
      username: e.detail.value
    })
    console.log("username", this.data.username)
  },
  forUserId: function(e) {
    this.setData({
      userId: e.detail.value
    })
    console.log("userId", this.data.userId)
  },
  onQuery: function() {
    const db = wx.cloud.database()
    //   counters
    db.collection('exam-userinfo').where({
      username: this.data.username
    }).get({
      success: res => {
        wx.showToast({
          title: ' '
        })
        wx: wx.navigateTo({
          url: '/pages/second/second'
        })
        console.log('[ ] [ ]  : ', res)
      },
      fail: err => {
        console.error('[ ] [ ]  :', err)
      }
    })
  },
  onAdd: function() {
    const db = wx.cloud.database()
    db.collection('exam-userinfo').add({
      data: {
        username: this.data.username,
        userId: this.data.userId
      },
      success: res => {
        wx: wx.showToast({
          title: ' '
        })
        console.log('[ ] [ ]  ,  _id: ', res._id)
      },
      fail: err => {
        console.error('[ ] [ ]  :', err)
      }
    })
  },
})
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.