qq_31205277 2018-08-22 03:01 采纳率: 40%
浏览 16124
已采纳

微信小程序自定义组件在获取到父组件传的值以后如何修改自定义内部数据??

父组件index.wxml stalls是个数组 count的属性是字符串

<view class='stalls' wx:for="{{stalls}}" wx:key=''>
    <stars count="{{item.count}}" />
  </view>
</view>

自定义组件
stars.wxml

   <view class='stall'>
  <view>{{count}}</view>
    <block wx:for="{{solid}}" wx:key="">  
      <image src='../../images/star-solid.png'></image>  
    </block>  
    <block wx:for="{{half}}" wx:key="">  
      <image src='../../images/star-half.png'></image>  
    </block>
    <block wx:for="{{hollow}}" wx:key="">  
      <image src='../../images/star-hollow.png'></image>  
    </block>  
  </view>

stars.js

 Component({
  properties: {
    count:String
  },
  data: {
    // 这里是一些组件内部数据
    solid: ' ', 
    half: ' ', 
    hollow: ' ', 
  },
    onLoad: function () {
      this.setData({ 
        solid: parseInt(this.properties.count),
        half: Math.ceil(5 - this.aproperties.count) - (5 - self.properties.count),
        hollow: parseInt(5 - this.properties.count)
      })
    },
})

自定义组件内部的data里的数据没有变化

  • 写回答

4条回答 默认 最新

  • Go 旅城通票 2018-08-22 13:22
    关注

    第一,组件没有onLoad事件,自己好好看api,改为ready事件
    https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/component.html

    第二,starts.js代码有问题,properties写成了aproperties,self变量没有定义;乱用

    
    Component({
      properties: {
        count: String
      },
      data: {
        // 这里是一些组件内部数据
        solid: '',
        half: '',
        hollow: '',
      },
      ready: function () {
        this.setData({
          solid: parseInt(this.properties.count),
          half: Math.ceil(5 - this.properties.count) - (5 - this.properties.count),
          hollow: parseInt(5 - this.properties.count)
        })
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题