亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home WeChat Applet Mini Program Development How to apply block in small program development

How to apply block in small program development

Jun 12, 2018 am 10:14 AM
Block WeChat applet

這次給大家?guī)?lái)小程序開(kāi)發(fā)中怎樣應(yīng)用block,小程序開(kāi)發(fā)中使用block的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來(lái)看一下。

經(jīng)過(guò)一年的發(fā)展,微信小程序發(fā)展火熱,本期就介紹下小程序的一些使用。

在安卓中我們經(jīng)常會(huì)使用ListView/GradeView/RecyclerView來(lái)實(shí)現(xiàn)展示循環(huán)數(shù)據(jù)。那么小程序中怎么到呢。其實(shí)很簡(jiǎn)單,使用block就可以了。

下面我們先看下效果圖:

這個(gè)布局其實(shí)很簡(jiǎn)單,大致分為3部分,上+下(左75%,右25%)。這里就不在細(xì)說(shuō)了。那么這里要怎么寫wxml呢。下面貼代碼:

這邊很清晰的可以看出這對(duì)標(biāo)簽,而數(shù)據(jù)源便是wx:for="{{goodlist}}"中的goodlist了。接著往下走,我們可以看到點(diǎn)擊標(biāo)簽的時(shí)候有bindtap事件,這里就不做說(shuō)明了。我們重點(diǎn)看下{{item.StartCity}},這是什么意思呢,其實(shí)這就是獲取數(shù)據(jù)源中的數(shù)據(jù),而item代表的是goodlist中的一條數(shù)據(jù),StrrtCity等都是數(shù)據(jù)源中的一些具體屬性。你可以更據(jù)需要直接調(diào)頭你想要的字段名就可以了。block到此基本結(jié)束了。最后此處設(shè)置了一個(gè)view,用來(lái)代替當(dāng)數(shù)據(jù)源為空時(shí)顯示無(wú)數(shù)據(jù)頁(yè)面提示。

下面順便介紹下數(shù)據(jù)格式處理(時(shí)間格式轉(zhuǎn)化):

在實(shí)際場(chǎng)景中我們可能會(huì)需要將時(shí)間轉(zhuǎn)化為幾分鐘前,幾小時(shí)前,幾天前等。那么我們數(shù)據(jù)庫(kù)中存放的一般是datetime格式數(shù)據(jù)。我們需要轉(zhuǎn)化處理。

處理時(shí)間的時(shí)候需要注意的是:ios和android上的時(shí)間格式不同。ios時(shí)間是以2018/04/01,所以需要先將時(shí)間格式轉(zhuǎn)化為/格式。不然你的小程序時(shí)間轉(zhuǎn)化只會(huì)對(duì)安卓生效哦。具體轉(zhuǎn)化代碼:

for?(var?i?=?0;?i?< goodsList.length; i++) {
 var PublishDatetime = goodsList[i].PublishDatetime.replace(/([\d\-]+)T(\d+:\d+)\:.*/, "$1 $2");//將帶T的時(shí)間格式轉(zhuǎn)化掉.
   PublishDatetime = PublishDatetime.replace(/-/g, "/");// 將格式‘-&#39;轉(zhuǎn)化為‘/&#39;
//換算時(shí)間戳,計(jì)算得到與當(dāng)前時(shí)間的差距
   var minute = 1000 * 60;
   var hour = minute * 60;
   var day = hour * 24;
   var halfamonth = day * 15;
   var month = day * 30;
   var now = new Date().getTime();
   var diffValue = now - new Date(PublishDatetime).getTime();
   //console.log("diffValue:" + diffValue);
   if (diffValue < 0) {
   return;
   }
   var monthC = diffValue / month;
   var weekC = diffValue / (7 * day);
   var dayC = diffValue / day;
   var hourC = diffValue / hour;
   var minC = diffValue / minute;
   if (monthC >=?1)?{
???if?(monthC?<= 12)
    goodsList[i].PublishDatetime = "" + parseInt(monthC) + "月前";//將時(shí)間替換掉想要的數(shù)據(jù)
   else {
    goodsList[i].PublishDatetime = "" + parseInt(monthC / 12) + "年前";//將時(shí)間替換掉想要的數(shù)據(jù)
   }
   }
   else if (weekC >=?1)?{
???goodsList[i].PublishDatetime?=?""?+?parseInt(weekC)?+?"周前";//將時(shí)間替換掉想要的數(shù)據(jù)
???}
???else?if?(dayC?>=?1)?{
???goodsList[i].PublishDatetime?=?""?+?parseInt(dayC)?+?"天前";//將時(shí)間替換掉想要的數(shù)據(jù)
???}
???else?if?(hourC?>=?1)?{
???goodsList[i].PublishDatetime?=?""?+?parseInt(hourC)?+?"小時(shí)前";//將時(shí)間替換掉想要的數(shù)據(jù)
???}
???else?if?(minC?>=?1)?{
???goodsList[i].PublishDatetime?=?""?+?parseInt(minC)?+?"分鐘前";//將時(shí)間替換掉想要的數(shù)據(jù)
???}?else?{
???goodsList[i].PublishDatetime?=?"剛剛";//將時(shí)間替換掉想要的數(shù)據(jù)
???}
??}
?//最后將轉(zhuǎn)化后的時(shí)間重新賦值給數(shù)據(jù)源

相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!

推薦閱讀:

極度簡(jiǎn)介執(zhí)行vue.watch

vue axios調(diào)用接口時(shí)請(qǐng)求超時(shí)

The above is the detailed content of How to apply block in small program development. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xianyu WeChat mini program officially launched Xianyu WeChat mini program officially launched Feb 10, 2024 pm 10:39 PM

Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

Implement image filter effects in WeChat mini programs Implement image filter effects in WeChat mini programs Nov 21, 2023 pm 06:22 PM

Implementing picture filter effects in WeChat mini programs With the popularity of social media applications, people are increasingly fond of applying filter effects to photos to enhance the artistic effect and attractiveness of the photos. Picture filter effects can also be implemented in WeChat mini programs, providing users with more interesting and creative photo editing functions. This article will introduce how to implement image filter effects in WeChat mini programs and provide specific code examples. First, we need to use the canvas component in the WeChat applet to load and edit images. The canvas component can be used on the page

Implement the drop-down menu effect in WeChat applet Implement the drop-down menu effect in WeChat applet Nov 21, 2023 pm 03:03 PM

To implement the drop-down menu effect in WeChat Mini Programs, specific code examples are required. With the popularity of mobile Internet, WeChat Mini Programs have become an important part of Internet development, and more and more people have begun to pay attention to and use WeChat Mini Programs. The development of WeChat mini programs is simpler and faster than traditional APP development, but it also requires mastering certain development skills. In the development of WeChat mini programs, drop-down menus are a common UI component, achieving a better user experience. This article will introduce in detail how to implement the drop-down menu effect in the WeChat applet and provide practical

What is the name of Xianyu WeChat applet? What is the name of Xianyu WeChat applet? Feb 27, 2024 pm 01:11 PM

The official WeChat mini program of Xianyu has been quietly launched. It provides users with a convenient platform that allows you to easily publish and trade idle items. In the mini program, you can communicate with buyers or sellers via private messages, view personal information and orders, and search for the items you want. So what exactly is Xianyu called in the WeChat mini program? This tutorial guide will introduce it to you in detail. Users who want to know, please follow this article and continue reading! What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3.

Moondrop releases Block true wireless earbuds with low-latency game mode Moondrop releases Block true wireless earbuds with low-latency game mode Aug 10, 2024 pm 03:31 PM

Moondrop has released the Block true wireless earbuds for audio enthusiasts that sit comfortably in the outer ear. Unlike earbuds jammed into ear canals, the Block does not cause a plugged ear feeling or collect ear wax. The 13 mm driver is enclosed

WeChat applet implements image upload function WeChat applet implements image upload function Nov 21, 2023 am 09:08 AM

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat

Implement image rotation effect in WeChat applet Implement image rotation effect in WeChat applet Nov 21, 2023 am 08:26 AM

To implement the picture rotation effect in WeChat Mini Program, specific code examples are required. WeChat Mini Program is a lightweight application that provides users with rich functions and a good user experience. In mini programs, developers can use various components and APIs to achieve various effects. Among them, the picture rotation effect is a common animation effect that can add interest and visual effects to the mini program. To achieve image rotation effects in WeChat mini programs, you need to use the animation API provided by the mini program. The following is a specific code example that shows how to

Use WeChat applet to achieve carousel switching effect Use WeChat applet to achieve carousel switching effect Nov 21, 2023 pm 05:59 PM

Use the WeChat applet to achieve the carousel switching effect. The WeChat applet is a lightweight application that is simple and efficient to develop and use. In WeChat mini programs, it is a common requirement to achieve carousel switching effects. This article will introduce how to use the WeChat applet to achieve the carousel switching effect, and give specific code examples. First, add a carousel component to the page file of the WeChat applet. For example, you can use the &lt;swiper&gt; tag to achieve the switching effect of the carousel. In this component, you can pass b

See all articles