修改默认的收货地址获取用户当前收货地址id 以及用户id更新当前用户的所有收货地址的默认收货地址状态为0更新当前收货地址的默认收货地址状态为1routerrouter.get(’/user/changeDefaultAddress’, initMiddleware, userauthMiddleware, controller.default.address.changeDefaultAddress);controllerapp/controller/default/address.js async changeDefaultAddress() { const uid = this.ctx.service.cookies.get(‘userinfo’)._id; var id = this.ctx.request.query.id; await this.ctx.model.Address.updateMany({ uid: uid }, { default_address: 0 }); await this.ctx.model.Address.updateMany({ uid: uid, “_id”: id }, { default_address: 1 }); this.ctx.body = { success: true, msg: ‘更新默认收货地址成功’ }; }viewapp/view/default/checkout.html $("#addressList .J_addressItem").click(function() { $(this).addClass(‘selected’).siblings().removeClass(‘selected’); var id = $(this).attr(‘data-id’); //收货地址的_id $.get(’/user/changeDefaultAddress?id=’ + id, function(response) { //console.log(response); }) })效果修改收货地址routerrouter.get(’/user/getOneAddressList’, initMiddleware, userauthMiddleware, controller.default.address.getOneAddressList);router.post(’/user/editAddress’, initMiddleware, userauthMiddleware, controller.default.address.editAddress);controllerapp/controller/default/address.js获取一个收货地址 async getOneAddressList() { const uid = this.ctx.service.cookies.get(‘userinfo’)._id; var id = this.ctx.request.query.id; var result = await this.ctx.model.Address.find({ uid: uid, “_id”: id }); this.ctx.body = { success: true, result: result, }; }编辑收货地址 async editAddress() { const uid = this.ctx.service.cookies.get(‘userinfo’)._id; const id = this.ctx.request.body.id; const name = this.ctx.request.body.name; const phone = this.ctx.request.body.phone; const address = this.ctx.request.body.address; const zipcode = this.ctx.request.body.zipcode; await this.ctx.model.Address.updateOne({ “_id”: id, “uid”: uid }, { name, phone, address, zipcode }); const addressList = await this.ctx.model.Address.find({ uid }).sort({ default_address: -1 }); this.ctx.body = { success: true, result: addressList, }; }效果