日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
從微信小程序到鴻蒙JS開發(fā)【04】-list組件

想了解更多內(nèi)容,請訪問:

和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos./#zz

1、可滾動區(qū)域

在許多場景中,頁面會有一塊區(qū)域是可滾動的,比如這樣一個簡單的每日新聞模塊:

上面的新聞類型是一塊可橫向滾動的區(qū)域,下方新聞列表是一塊可豎向滾動的區(qū)域。在微信小程序中,使用scroll-view組件即可實現(xiàn)。那么在鴻蒙js組件中,想要實現(xiàn)可滾動的區(qū)域,則是使用list組件。list僅支持豎向滾動,橫向滾動要用tabs,將在下篇博客講解。

2、list + list-item

這里以本地新聞模塊為例,數(shù)據(jù)請求自天行數(shù)據(jù)接口(https://www.tianapi.com/apiview/154)。

上方為一個搜索框,下方是新聞列表。搜索框給了固定高度,那么怎樣讓新聞列表能夠占滿屏幕剩余部分呢?只需將父容器設置flex布局,list設置flex: 1即可。list下直接放list-item,在總高度超出list的高度后,即可上下滾動。

hml:

 
 
 
 
  1.  
  2.      
  3.          
  4.          
  5.      
  •      
  •          
  •              
  •                  
  •                      
  •                          {{ $item.title }}
  •                      
  •                      
  •                          
  •                              {{ $item.source }}
  •                          
  •                          
  •                              {{ $item.ctime }}
  •                          
  •                      
  •                  
  •              
  •          
  •      
  •  
  •  
  • css:

     
     
     
     
    1. /*本地新聞*/
    2. .searchView {
    3.     width: 100%;
    4.     height: 140px;
    5.     background-color: #f0f0f0;
    6.     display: flex;
    7.     align-items: center;
    8. }
    9. .searchView>image {
    10.     margin: 0 40px 0 40px;
    11.     height: 60px;
    12.     width: 60px;
    13. }
    14. .searchView>input {
    15.     margin-right: 40px;
    16. }
    17. .localView {
    18.     width: 100%;
    19.     flex: 1;
    20.     display: flex;
    21.     flex-direction: column;
    22. }
    23. .localContent {
    24.     margin-left: 20px;
    25. }
    26. .newsItem {
    27.     width: 100%;
    28.     height: 240px;
    29.     border-bottom: 1px solid #bbbbbb;
    30.     display: flex;
    31.     align-items: center;
    32. }
    33. .newsContent {
    34.     display: flex;
    35.     flex-direction: column;
    36.     margin-right: 20px;
    37.     margin-left: 20px;
    38. }
    39. .newsContent>text {
    40.     margin-top: 20px;
    41.     height: 140px;
    42.     font-size: 34px;
    43.     color: #333333;
    44. }
    45. .newsDesc {
    46.     height: 60px;
    47.     line-height: 60px;
    48.     display: flex;
    49.     justify-content: space-between;
    50. }
    51. .newsDesc>text {
    52.     font-size: 28px;
    53.     color: #777777;
    54. }

     js:

     
     
     
     
    1. searchLocalNews() {
    2.      let url = 'http://api.tianapi.com/areanews/index?key=xxxx&areaname=江蘇';
    3.      if (this.searchWord) {
    4.          url = url + '&word' + this.searchWord;
    5.      }
    6.      fetch.fetch({
    7.          url: url,
    8.          responseType: 'json',
    9.          success: res => {
    10.              let data = JSON.parse(res.data);
    11.              this.localNews = data.newslist;
    12.          }
    13.      })
    14.  },

     新聞列表可滾動,且不會影響搜索框的位置。

    3、list + list-item-group + list-item

    list組件的子元素還可以是list-item-group,顧名思義應是分組列表項,list-item作為list-item-group的子元素。隨便寫一點看一看:

     
     
     
     
    1.         
    2.             
    3.                 
    4.                     
    5.                         分組1 子項1
    6.                     
    7.                 
    8.                 
    9.                     
    10.                         分組1 子項2
    11.                     
    12.                 
    13.                 
    14.                     
    15.                         分組1 子項3
    16.                     
    17.                 
    18.             
    19.             
    20.                 
    21.                     
    22.                         分組2 子項1
    23.                     
    24.                 
    25.                 
    26.                     
    27.                         分組2 子項2
    28.                     
    29.                 
    30.                 
    31.                     
    32.                         分組2 子項3
    33.                     
    34.                 
    35.             
    36.         
    37.     

     
     
     
     
    1. .manageList{
    2.     height: 100%;
    3.     width: 100%;
    4. }
    5. .list-item-group{
    6.     width: 100%;
    7.     height: 450px;
    8. }
    9. .list-item{
    10.     width: 100%;
    11.     height: 150px;
    12.     display: flex;
    13.     justify-content: center;
    14.     align-items: center;
    15.     border-bottom: 1px solid gray;
    16. }
    17. .list-item>text{
    18.     line-height: 100px;
    19. }

    可以看出,list-item-group是可折疊的列表分組,且默認是折疊的。點擊右側(cè)小箭頭可展開列表,如果list-item-group給了高度,則折疊和展開后這一塊區(qū)域的高度不變。在折疊時,展示第一個list-item的內(nèi)容。

    那么如果每一個list-item-group中l(wèi)ist-item數(shù)目不固定,在展開后的布局就會很難看。如下:

    其實不定義list-item-group的高度即可,折疊高度為list-item的高度,展開后高度自適應增長,超出list高度可以滾動,功能還是很強大的。更改css后的效果如下:

    這種分組的列表,可以制作一個簡單的后臺管理系統(tǒng)菜單界面。這里我將菜單數(shù)據(jù)文件、圖片文件放入nginx服務器的目錄中,再通過內(nèi)網(wǎng)穿透訪問資源。注意數(shù)據(jù)的格式,list-item-group和list-item之間存在父級標簽關系,故數(shù)據(jù)中也應存在父級關系。list-item-group展示的內(nèi)容是其下第一個list-item,這里用一個兩重for循環(huán)實現(xiàn):

    manage.json:

     
     
     
     
    1. {
    2.     "manageList": [
    3.         {
    4.             "name": "組織管理",
    5.             "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/org.png",
    6.             "subList": [
    7.                 {
    8.                     "name": "查詢組織",
    9.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/search.png"
    10.                 },
    11.                 {
    12.                     "name": "添加組織",
    13.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/add.png"
    14.                 },
    15.                 {
    16.                     "name": "刪除組織",
    17.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/delete.png"
    18.                 }
    19.             ]
    20.         },
    21.         {
    22.             "name": "人員管理",
    23.             "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/person.png",
    24.             "subList": [
    25.                 {
    26.                     "name": "查詢?nèi)藛T",
    27.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/search.png"
    28.                 },
    29.                 {
    30.                     "name": "添加人員",
    31.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/add.png"
    32.                 },
    33.                 {
    34.                     "name": "批量導入人員",
    35.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/add.png"
    36.                 },
    37.                 {
    38.                     "name": "刪除人員",
    39.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/delete.png"
    40.                 },
    41.                 {
    42.                     "name": "修改人員",
    43.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/update.png"
    44.                 }
    45.             ]
    46.         },
    47.         {
    48.             "name": "卡片管理",
    49.             "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/card.png",
    50.             "subList": [
    51.                 {
    52.                     "name": "開卡",
    53.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/add.png"
    54.                 },
    55.                 {
    56.                     "name": "退卡",
    57.                     "icon": "http://milkytea.free.idcfengye.com/images/christools/icon/delete.png"
    58.                 }
    59.             ]
    60.         }
    61.     ]
    62. }

     hml:

     
     
     
     
    1.      
    2.          
    3.              
    4.                  
    5.                      
    6.                          
    7.                          {{ $item.name }}
    8.                      
    9.                      
    10.                          
    11.                              
    12.                              {{ value.name }}
    13.                          
    14.                      
    15.                  
    16.              
    17.          
    18.      
  •      
  • js:

     
     
     
     
    1. getManageList() {
    2.        let url = "http://milkytea.free.idcfengye.com/text/manage.json";
    3.        fetch.fetch({
    4.            url: url,
    5.            responseType: 'json',
    6.            success: res => {
    7.                let data = JSON.parse(res.data);
    8.                this.manageList = data.manageList;
    9.            }
    10.        })
    11.    }

     想了解更多內(nèi)容,請訪問:

    和華為官方合作共建的鴻蒙技術(shù)社區(qū)

    https://harmonyos./#zz


    分享文章:從微信小程序到鴻蒙JS開發(fā)【04】-list組件
    當前路徑:http://www.dlmjj.cn/article/djesscs.html