2***@qq.com
2***@qq.com
  • 发布:2020-11-12 11:23
  • 更新:2022-10-20 20:11
  • 阅读:3620

uni-clientdb组件 关于where属性使用变量进行查询的问题

分类:uniCloud

官方文档中,所有where属性都是使用写死的字符串进行查询的,这在实际项目中基本不常用

<uni-clientdb v-slot:default="{data, loading, error, options}" collection="user" field="name" :getone="true" where="id=='1'">  
      <view>  
          {{ data.name}}  
      </view>  
    </uni-clientdb>

于是我尝试用组件的变量来写,如下:(注意where前已经加了冒号,where中的the_data是从父组件中传入的参数)

<uni-clientdb ref="udb" v-slot:default="{data, loading, error, options}"  collection="article" :where="_id==the_data._id" :getone="true">  
{{data}}  
</uni-clientdb>

结局是报错
Property or method "_id" is not defined on the instance but referenced during render.
Property or method "data" is not defined on the instance but referenced during render

我是个小白,所以不太清楚该怎么写
但是通过之前的一些奇怪的经验,我摸索出了能够达成效果的写法,就是放弃官方文档说的这种jql写法,where里的语句用mongdb的方式去写:

<uni-clientdb ref="udb" v-slot:default="{data, loading, error, options}"  collection="article" :where="{_id:the_data._id}" :getone="true">  
{{data}}  
</uni-clientdb>

就成功了……
所以问题来了,jql该怎么写?

2020-11-12 11:23 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

  • 如果你写在模板里面就是这样的

    :where = "'_id==\"'+the_data._id+'\"'"  
  • 如果用computed

    where(){  
      return `_id=="${this.the_data._id}"`  
    }  

    模板里面这么写

    :where="where"  
2***@qq.com

2***@qq.com

请问多个where条件该怎么写?

q***@163.com

q***@163.com

这个问题解决了吗?我遇到同样的问题:

    <unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" collection="goods_pack_way"   
    field="goods_pack_name" :where="sWhere">  
this.sWhere = "goods_id == "  + this.goods_id

在H5内能正常,在微信小程序中,where不起作用!

  • q***@163.com

    已解决,坑有点深,需要设置loadtime属性

    2021-07-05 15:10

  • DCloud_uniAD_HDX

    回复 q***@163.com: this.swhere 写在了什么位置?组件默认是自动请求数据,在请求数据的过程中,修改属性会被忽略掉,如有问题请联系QQ: 87263426

    2021-07-06 14:23

  • 7***@qq.com

    这个问题 我也测试很多次 反正没搞懂这个组件内部是在父组件什么时候开始请求数据的, 传早了不行因为你的变量还没拿到,所以我都是等他内部查一次延迟再传一次才行, 反正不如自己写jql方便

    2021-07-23 15:44

  • 不将就1207

    回复 q***@163.com: 遇到同样的问题,怎么解决的?

    2021-11-16 11:52

  • q***@163.com

    回复 3***@qq.com: 后来也是设置loadtime解决的

    2021-11-29 16:32

myforr

myforr

这样对了

<uni-data-picker  
        v-model="formData.parent_id"  
        placeholder="请选择父级"   
        popup-title="请选择父级"   
        collection="app_images_categories"   
        field="_id as value, name as text"   
        orderby="_id asc"   
        self-field="_id"   
        parent-field="parent_id"  
        :where="`_id!='${formDataId}'`"  
        @nodeclick = "onnodeclick"  
        @popupclosed="onpopupclosed"  
        ></uni-data-picker>

要回复问题请先登录注册