不應該這樣寫'data.inputValue', 如果一個對象是,userinfo:{ins:1},可以寫成'userinfo.ins'這樣 ps: this.setData({ inputValue:"258963", 'userinfo.ins':"2589" })
在事件函數中傳值給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" })
上面定義:inputValue:" ",
下面使用:console.log("搜索"+this.data.inpuVaue)
this.setData你可以理解為異步的,所以底下直接用是不行的.
我記得好像setDate的時候,不需要data吧,你試試
`this.setData({ 'showClearBtn': val != '' ? true : false, 'inputValue':e.detail.value })`
樓上一看就是寫react的,你這寫法不對,this.data['data.inpuVaue'],這樣就有值了。
this.setData({ a: 1, }) console.log(this.data.a); //1
我想在這個遍歷中通過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
app.js
app.wxml
app.wxss