小程序模板网

微信小程序开发问答《六十四》赋值undefined & wx for中对满足条件的项添加class

发布时间:2018-04-23 11:47 所属栏目:小程序开发教程
1、微信小程序,每次修改自动编译后都会跳首页问题
 
在app.json中,page数组里,把你正在调试的page放在最上面

 

 

2、微信小程序赋值undefined 新手求解

在事件函数中传值给data 中的inputValue变量 但是实际上inputValue的值确实undefined 具体原因是在查不清楚 求各位帮帮忙 感谢 网上给出的一些方法都尝试过还是不行

  data: {
    inputValue:" ",
    resultset: [{text:"aaa"},{text:"bbb"}, {text: 'ccc'}, {text: 'f' }],
    
    showClearBtn: false

  
  },
searchActiveChangeinput: function (e) {
     const val =e.detail.value
     console.log("输入"+val)
     this.setData({
       'data.showClearBtn': val != '' ? true : false,
       'data.inputValue':e.detail.value
     })
     console.log("搜索"+this.data.inpuVaue)
  },

答:

不应该这样写'data.inputValue',
如果一个对象是,userinfo:{ins:1},可以写成'userinfo.ins'这样
ps:
this.setData({
   inputValue:"258963",
    'userinfo.ins':"2589"
})
0

上面定义:inputValue:" ",
下面使用:console.log("搜索"+this.data.inpuVaue)

0

this.setData你可以理解为异步的,所以底下直接用是不行的.

0

我记得好像setDate的时候,不需要data吧,你试试

`this.setData({
   'showClearBtn': val != '' ? true : false,
   'inputValue':e.detail.value
 })`
 
0

楼上一看就是写react的,你这写法不对,this.data['data.inpuVaue'],这样就有值了。

this.setData({
  a: 1,
})
console.log(this.data.a);
//1

 

3、wx for中对满足条件的项添加class

 

我想在这个遍历中通过daysList数组下标和 另外一个数组中的值进行比较,如果相等则添加类名checked,就是一个背景图标。底下代码中添加的类名thisDay只是一个标签的类。

请输入代码

<text wx:for="{{daysList}}" wx:key="*this" wx:for-index="idx" word-wrap:="" break-word;="" margin:="" 0px;="" padding:="" 0px;"="" 1.5em="" color:="" font-family:="" helvetica="" pingfang="" hiragino="" sans="" wenquanyi="" micro="" microsoft="" line-height:="" background-color:="">这个是另一个数组:

<view wx:for="{{signDays}}" wx:for-item="jitem">{{jitem}}view>

想把两个数组的内容关联起来,不知道怎么办,请大神指导下该怎么弄。绝望中...

 

答:那你在视图层肯定是不行的,感觉要在js里去遍历然后再在视图层去wx:if

 

4、微信小程序:隐藏和显示功能

app.js

 

			
  1. Page({
  2. data:{
  3. showView:true
  4. },
  5. onLoad:function(options){
  6. // 生命周期函数--监听页面加载
  7. showView:(options.showView=="true"?true:false)
  8. }
  9. ,onChangeShowState:function(){
  10. var that=this;
  11. that.setData({
  12. showView:(!that.data.showView)
  13. })
  14. }
  15. })

app.wxml

 

			
  1. [html] view plain copy
  2. <viewclassviewclass="page">
  3. <view >
  4. <buttonbindtapbuttonbindtap="onChangeShowState">{{showView?'隐藏':'显示'}}button>
  5. view>
  6. <view class="bright789_view_hide{{showView?'bright789_view_show':''}}">
  7. <textclasstextclass="bright789-text">我是被显示被隐藏控件text>
  8. view>
  9. view>

app.wxss

 

			
  1. [html] view plain copy
  2. .bright789-text{
  3. font-size: 40rpx;
  4. line-height: 40px;
  5. color: #ff0000;
  6. }
  7. .bright789_view_hide{
  8. display: none;
  9. }
  10. .bright789_view_show{
  11. display: block;
  12. }
 
 
 


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/23925.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询