We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
###父组件
<template> <button @tap="fetchCate">父测试</button> // 按这个测试按钮,能打印获取 cates 的结果。但依然没能显示在下面的 checkbox 中。 <view class="weui-cells__title">商品分类</view> <button @tap="showCate">{{cateBtnTxt}}</button> <view wx:if="{{isShowCate}}"> <!-- 由于 cates 是异步得到的结果,所以需要 .sync。 --> <checkbox :cates.sync="cates" :chkCateIds="chkCateIds" :chkCateIndex="chkCateIndex" :cateBtnTxt="cateBtnTxt"></checkbox> </view> </template>
import wepy from 'wepy' import Uploader from '../components/uploader' import Checkbox from '../components/checkbox' import AV from '../libs/av-weapp-min' export default class Index extends wepy.page { config = { navigationBarTitleText: '新建商品' } components = { checkbox: Checkbox } data = { cates: [], chkCateIndex: [], cateBtnTxt: '选择分类', } async fetchCate() { let query = new AV.Query('Cate') let downloadCates = await query.find() let i = 0; // 把 Cate 的对象装入一个有 index 的列表,用于记录已经选择的分类。 // 以后修改产品属性的时候,从云端获取产品,可以先勾选后已经选择的分类。 for (let cate of downloadCates) { this.cates[i] = {index: i, cate} i ++ } console.log(this.cates) this.$apply() } onLoad() { this.fetchCate() } }
在PC 上,打开后就能加载到 cates 并能显示出来。而在真机却不能,点击上面测试按钮,也证实能在云端获取数据,但是就是不能加载到 this.cates 那里,所以显示不了对吗?还是因为其他原因 cates 未能传过去子组件?
###子组件
<template> <view class="weui-cells weui-cells_after-title"> <checkbox-group @change="checkboxChange"> <label class="weui-cell weui-check__label" wx:for="{{cates}}" wx:for-index="idx" wx:key="objectId"> <checkbox value="{{item.index}}" checked="{{item.checked}}"/>{{item.cate.name}} </label> </checkbox-group> <view class="weui-cell weui-cell_link"> <view class="weui-cell__bd">添加更多</view> </view> <view class="cateBtns"> <button type="warn" class="cateBtn">删除</button> <button @tap="checkCate" type="primary" class="cateBtn">确认</button> </view> </view> </template>
import wepy from 'wepy' import AV from '../libs/av-weapp-min' export default class Checkbox extends wepy.component { props = { cates: Array, chkCateIndex: { type: Number, twoWay: true // 可以用表达式 }, cateBtnTxt: { type: String, twoWay: true // 可以用表达式 } } methods = { checkboxChange(e) { let indexes = e.detail.value console.log(indexes) this.chkCateIndex = indexes for (let cate of this.cates) { cate.checked = false } let names = [] for (let i of indexes) { this.cates[i].checked = true names = [...names, this.cates[i].cate.attributes.name] } if (names.length > 0) { let nameTxt = names.join(' ') this.cateBtnTxt = '已选择分类: ' + nameTxt } else { this.cateBtnTxt = '选择分类' } } } onLoad() { } }
The text was updated successfully, but these errors were encountered:
看看是不是这个问题 #270
Sorry, something went wrong.
如果没有问题就close掉这个ISSUE
No branches or pull requests
###父组件
在PC 上,打开后就能加载到 cates 并能显示出来。而在真机却不能,点击上面测试按钮,也证实能在云端获取数据,但是就是不能加载到 this.cates 那里,所以显示不了对吗?还是因为其他原因 cates 未能传过去子组件?
###子组件
The text was updated successfully, but these errors were encountered: