|
- <template>
- <list-view id="listView" class="main" enable-back-to-top onscrolltolower={this.onscrolltolower}
- cell-type-key="type">
- <cell class="cell1" onclick={this.itemClick} cell-type="1111">
- <text class="title">1111{item.title}</text>
- <text class="subtitle">{item.subtitle}</text>
- </cell>
- <cell class="cell2" onclick={this.itemClick} cell-type="2222">
- <text class="title">2222{item.title}</text>
- <text class="subtitle">{item.subtitle}</text>
- </cell>
- <cell class="cell2" onclick={this.itemClick} cell-type="3333">
- <text class="title">3333{item.title}</text>
- <text class="subtitle">{item.subtitle}</text>
- </cell>
- <list-footer class="footer">
- <text>加载中...</text>
- </list-footer>
- </list-view>
- </template>
- <style>
- .main {
- width: 100%;
- height: 100%;
- }
- .cell1 {
- padding: 8px;
- height: 60px;
- border-bottom: 0.5px solid rgb(91, 190, 60);
- background-color: rgb(241, 82, 82);
- }
- .cell2 {
- padding: 8px;
- height: 60px;
- border-bottom: 0.5px solid #ddd;
- background-color: rgb(104, 33, 235);
- }
- .cell:active {
- background-color: #ddd;
- }
- .title {
- font-weight: bold;
- font-size: 18px;
- color: #000;
- }
- .subtitle {
- color: #333;
- }
- .footer {
- justify-content: center;
- align-items: center;
- }
- </style>
- <script>
- export default {
- name: 'test',
- methods: {
- apiready() {
- this.initData(false);
- },
- initData(loadMore) {
- var that = this;
- var skip = that.dataList ? that.dataList.length : 0;
- var dataList = [];
- for (var i = 0; i < 20; i++) {
- dataList[i] = {
- title: '项目' + (i + skip),
- subtitle: '这里是子标题',
- type: i % 2 === 0 ? '1111' : '2222'
- };
- }
- var listView = document.getElementById('listView');
- if (loadMore) {
- that.dataList = that.dataList.concat(dataList);
- listView.insert({
- data: dataList
- });
- } else {
- that.dataList = dataList;
- listView.load({
- data: dataList
- });
- }
- },
- onscrolltolower() {
- this.initData(true);
- },
- itemClick(e) {
- api.alert({
- msg: '当前项索引:' + e.currentTarget.index
- });
- }
- }
- };
- </script>
复制代码 首先list-view在渲染内部的cell当有多种cell时,也就是你需要展示多种cell的种类或样式,这时会默认渲染第一种类型的cell,这样就无法展示其他类型的cell。使用cell-type-key字段绑定数组中的变量,可以理解是一个key,当cell-type中的值等于这个key时就会显示出来。这种渲染方式的好处是提高原生中的渲染性能。
|
|