当前位置:网站首页>微信小程序更改属性值-setData-双向绑定-model
微信小程序更改属性值-setData-双向绑定-model
2022-07-29 05:10:00 【程序猿向前跑】
如何对一个数组和对象更改里面的属性呢?
1、更改数组中的值
设 paraList:[{
txt:'123',chose:false},{
txt:'1234',chose:false}]
let choseChange = "paraList[" + index + "].chose"
_this.setData({
[choseChange]: true,
numList: numList
})
可以改变数组中某一个特定下标的值
2、更改对象中的值
userInfo: {
// 用户的验证信息
sex: '',
name: '',
phone: '',
code: '',
sexTxt:'请选择你的性别',
nameTxt:'名字不能为空',
phoneTxt: '手机号不能为空',
codeTxt: '获取验证码',
codeErrTxt:'验证码不能为空'
},
let userSex = "userInfo.sex"
_this.setData({
[userSex]: '1'
})
可以单独更改userInfo中的sex值
(1)非自定义组件中
<input model:value="{
{属性}}" />
不支持data中.路径的写法
如:<input model:value="{
{ a.b }}" />
(2)自定义组件Components中
1、定义传入的属性格式
Component({
properties: {
myValue: String
}
})
2、组件中使用
<input model:value="{
{myValue}}" />
3、引用该组件的地方
<custom-component model:my-value="{
{属性}}" /> my-value可以为任意字段,在组件中要写成驼峰的形式
https://blog.csdn.net/Shids_/article/details/125538656
边栏推荐
猜你喜欢

Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy

游戏行业弹性计算最佳实践

ClickHouse学习(三)表引擎

ClickHouse学习(五)集群操作

Day 3

Clickhouse learning (V) cluster operation

Alibaba cloud architect details nine trends in the game industry

ClickHouse学习(十一)clickhouseAPI操作

C language first level pointer

【JS题解】牛客网JS篇1-10题
随机推荐
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
D3d Shader Instruction
About local variables
Clickhouse learning (VIII) materialized view
一维数组练习
shell基本操作(下)
ClickHouse学习(三)表引擎
uniapp之常用提示弹框
【C语言系列】— 把同学弄糊涂的 “常量” 与 “变量”
Terminal shell common commands
End of document
浅谈Servlet
【C语言系列】—深度解剖数据在内存中的存储(一) 暑假开篇
携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
Realize simple database query (incomplete)
Application of Huffman tree and Huffman coding in file compression
Clickhouse learning (V) cluster operation
小程序中的DOM对象元素块动态排序
【C语言系列】— 字符串+部分转义字符详解+注释小技巧
Clickhouse learning (XI) clickhouseapi operation