微信小程序 實(shí)例應(yīng)用(記賬)詳解
更新時間:2016年09月28日 14:13:14 作者:756567406
這篇文章主要介紹了微信小程序 實(shí)例應(yīng)用(記賬)詳解的相關(guān)資料,需要的朋友可以參考下
微信小程序-記賬小應(yīng)用
github地址: https://github.com/HowName/account-note

var util = require("../../utils/util.js");
//獲取應(yīng)用實(shí)例
var app = getApp();
Page({
data: {
userInfo: {},
buttonLoading: false,
accountData:[],
accountTotal:0
},
onLoad: function () {
console.log('onLoad')
var that = this;
// 獲取記錄
var tempAccountData = wx.getStorageSync("accountData") || [];
this.caculateTotal(tempAccountData);
this.setData({
accountData: tempAccountData
});
},
// 計算總額
caculateTotal:function(data){
var tempTotal = 0;
for(var x in data){
tempTotal += parseFloat(data[x].amount);
}
this.setData({
accountTotal: tempTotal
});
},
//表單提交
formSubmit:function(e){
this.setData({
buttonLoading: true
});
var that = this;
setTimeout(function(){
var inDetail = e.detail.value.inputdetail;
var inAmount = e.detail.value.inputamount;
if(inDetail.toString().length <= 0 || inAmount.toString().length <= 0){
console.log("can not empty");
that.setData({
buttonLoading: false
});
return false;
}
//新增記錄
var tempAccountData = wx.getStorageSync("accountData") || [];
tempAccountData.unshift({detail:inDetail,amount:inAmount});
wx.setStorageSync("accountData",tempAccountData);
that.caculateTotal(tempAccountData);
that.setData({
accountData: tempAccountData,
buttonLoading: false
});
},1000);
},
//刪除行
deleteRow: function(e){
var that = this;
var index = e.target.dataset.indexKey;
var tempAccountData = wx.getStorageSync("accountData") || [];
tempAccountData.splice(index,1);
wx.setStorageSync("accountData",tempAccountData);
that.caculateTotal(tempAccountData);
that.setData({
accountData: tempAccountData,
});
}
})
通過此文,希望大家對微信小程序了解,并應(yīng)用,謝謝大家對本站的支持!
相關(guān)文章
Javascript基礎(chǔ)知識中關(guān)于內(nèi)置對象的知識
這篇文章主要介紹了Javascript基礎(chǔ)知識中關(guān)于內(nèi)置對象的相關(guān)知識的相關(guān)資料,需要的朋友可以參考下面小編薇大家?guī)淼木饰恼?/div> 2021-09-09
JavaScript嚴(yán)格模式不支持八進(jìn)制的問題講解
這篇文章主要講解JavaScript嚴(yán)格模式不支持八進(jìn)制的問題,本文圍繞JavaScript嚴(yán)格模式展開內(nèi)容,詳細(xì)介紹為什么JavaScript嚴(yán)格模式不支持八進(jìn)制,下面來看看詳細(xì)介紹,需要的朋友可以參考一下2021-11-11最新評論

