美文网首页
小程序入门学习08--云开发01

小程序入门学习08--云开发01

作者: 阿墨呦 | 来源:发表于2020-02-13 21:08 被阅读0次

1 数组查询
1)新建带云开发功能的小程序
2)点击云开发->数据库->新建集合->添加几条记录

在这里插入图片描述
3)编码
index.wxml
<button class="b1" bindtap="query">数组查询</button>

index.json

{}

index.wxss

.b1{
  background-color: #eee;
}

index.js

/ 初始化数据库实例 command
const db = wx.cloud.database();
const _ = db.command
Page({
  query:function(){
    console.log("Query")
    //查询所有内容 获取并输出
    //db.collection("data").get().then(console.log)
    //查询count为(in)1 3 4 的数据 不为是nin
    db.collection("data")
    .where({
      count:_.nin([1,3,4])
    })
    .get().then(console.log)
  }
})

2 字段类型查询
为已有数据添加字段,然后

db.collection("data")
    //查询desc字段
      .field({
        desc:true
      })
      .get().then(console.log)

3 正则表达式

db.collection("data")
      .where({
        //new正则对象
        name: new db.RegExp({
          //正则字符串 匹配name-01 ... name-09
          regexp: 'name-0[1-9]',
          options: 'i'
        })
      })
      .get().then(console.log)

4 地理位置查询
index.wxml

<button class="b1" bindtap="add">新增地点</button>
<button class="b1" bindtap="query">字段查询</button>

index.js

const db = wx.cloud.database();
const _ = db.command
Page({
  query: function () {
    console.log("Query")
    //数据0的读取维度 ;不用res拿到的是一个数组,所以使用回调函数res方便后续处理
    db.collection('location').get().then(res=>{
      console.log(res.data[0].location.latitude)
    })
  },
  //添加地理位置索引
  add:function(){
    db.collection('location').add({
      //data表示需新增的json数据
      data:{
        location:db.Geo.Point(100.0012,10.0022)
      }
      //then() 异步执行 then前程序执行完后,执行then内部数据(一层一层剥开你的心)
    }).then(res=>{
      db.collection('location').add({
        data:{
          location:db.Geo.Point(101.0012,10.0022)
        }
      }).then(res=>{
        db.collection('location').add({
          data: {
            //创建一个点
            location: db.Geo.Point(101.0012, 10.0022)
          }
        })
      })
    })
  }
})

领取限量云产品优惠

相关文章

  • 小程序入门学习08--云开发01

    1 数组查询1)新建带云开发功能的小程序2)点击云开发->数据库->新建集合->添加几条记录 index.json...

  • 小程序云开发教程(初识篇)

    目录一、为什么学小程序云开发二、小程序云开发是什么三、学习准备 系列教程小程序云开发教程(入门篇)小程序云开发教程...

  • 小程序云开发教程(地雷篇,持续更新)

    目录一、代码坑二、IDE缺陷 系列教程小程序云开发教程(初识篇)小程序云开发教程(入门篇) 一、代码坑 二、IDE...

  • 微信小程序知识全景思维导图

    微信小程序思维导图 腾讯云小程序学习地址 小程序开发文档 小程序开发社区

  • 微信小程序

    微信小程序入门 入门简易教程 小程序开发流程注册小程序->代码开发->提审->上线/审核未通过 开发者工具左侧模拟...

  • 小程序云开发入门

    1、在微信开发工具中新建小程序云开发模板,点击确定 2、创建test环境并部署环境,相当于mysql的数据库名字,...

  • 小程序云开发-入门

    创建小程序的时候,选择不使用云开发,不然的话会自动生成好多文件。自己创建配置就可以了 首先配置云函数存储的目录 操...

  • 小程序云开发入门

    最近用小程序的云开发功能写了个小程序,发现云开发这个东西真的是前端开发者的福音,因为你几乎不需要懂任何后端的东西就...

  • 小程序云开发入门

    1、开通云开发服务 点击微信开发者工具的“云开发”图标,在弹出框里点击“开通”,同意协议后,会弹出创建环境的对话框...

  • 小程序Cloud开发归纳

    小程序云开发 小程序·云开发是微信团队联合腾讯云推出的专业的小程序开发服务。开发者可以使用云开发快速开发小程序、小...

网友评论

      本文标题:小程序入门学习08--云开发01

      本文链接:https://www.haomeiwen.com/subject/zvtrfhtx.html