Like the title, I want to realize that when I click on a cell, that cell will change color to distinguish it from other cells, and it will be a single selection. Or how to get the cell object based on the index in the list
滿天的星座2017-05-16 13:30:43
Use active pseudo-class in css
<template>
<p>
<list class="list">
<cell
v-for="(v,i) in rows"
append="tree"
:index="i"
:key="i"
class="row">
<p class="item">
<text class="item-title">row {{v.id}}</text>
</p>
</cell>
</list>
</text>
</p>
</template>
<style scoped>
.list {
height:850px
}
.count {
font-size: 48px;
margin:10px;
}
.indicator {
height: 40px;
width: 40px;
color:#45b5f0;
}
.row {
width: 750px;
}
.item {
justify-content: center;
border-bottom-width: 2px;
border-bottom-color: #c0c0c0;
height: 100px;
padding:20px;
}
.item:active {
background-color: #00BDFF;
}
.item-title {
}
</style>
Please refer to http://weex.apache.org/cn/ref...
过去多啦不再A梦2017-05-16 13:30:43
To achieve a radio-select-like effect, you can probably do this:
Use the selected field of the current row to determine whether it is selected, thereby changing the background-color
Dom structure as follows:
<list>
<cell v-for="(item,index) in listData" v-bind:style="{'background-color':(item.selected?'#dddddd':'#ffffff')}" @click="onSelected(item,index)">
<p>
<text>{{item.text}}</text>
</p>
</cell>
</list>
The js structure is as follows:
data: {
"listData": [
{'text': '开发者头条', selected: false},
{'text': '腾讯新闻', selected: false},
{'text': '搜狐娱乐', selected: false},
{'text': '优酷视频', selected: false}
]
},
methods:{
"onSelected":function(item,index){
if (item.selected) {
this.listData[index].selected = false;
} else {
this.listData[index].selected = true;
}
}
}
Hope it can help you