Table of Contents
Implementation method
1. Implementation of preloading (two methods):
Preloading method one:
Preloading method two:
Comparison of two preloading methods:
2. Trigger custom events through mui.fire
Home Web Front-end HTML Tutorial How to optimize mui list to jump to details page

How to optimize mui list to jump to details page

Mar 19, 2018 pm 05:40 PM
list Details Go to

Because the list page to the details page is in a many-to-one format, that is, multiple data lists on the list page correspond to one details page, but the data is different; therefore, the details page can be preloaded when loading the list page, that is, Create a webview of the details page, but do not display it. When the list is clicked, the event of the details page is triggered through a specific method to obtain the response data. This approach can greatly shorten the response time.

Implementation method

  1. Load the details page in advance through preloading;

  2. mui.fire trigger Specify the event on the details page and call ajax to update the data;

1. Implementation of preloading (two methods):

Official address

Preloading method one:

Configure through the preloadPages parameter in the mui.init method.

mui.init({
  preloadPages:[
    {
      url:prelaod-page-url,      id:preload-page-id,
      styles:{},//窗口参数
      extras:{},//自定义扩展参数
      subpages:[{},{}]//预加载页面的子页面
    }
  ],
  preloadLimit:5//预加载窗口数量限制(一旦超出,先进先出)默认不限制});
Copy after login

In use, you may not use so many attributes. The following is my use case:

mui.init({    preloadPages: [{
        url: 'account_detail.html',
        id: 'account_detail.html'
    }]
});
Copy after login

You only need to set the url and id, which are required for the details page Parameters are passed when using mui.fire;

Preloading method two:

Preload through the mui.preload method.

var page = mui.preload({    url:new-page-url,    id:new-page-id,//默认使用当前页面的url作为id
    styles:{},//窗口参数
    extras:{}//自定义扩展参数});
Copy after login
Comparison of two preloading methods:

1. Method one creates a preloaded page asynchronously, and can create multiple pages at the same time, but because it is asynchronous, it cannot Get the created webview object immediately, and you need to use plus.webview.getWebviewById to get the created webview;
2. Method 2 is to create a preloaded page synchronously. You can get the webview synchronously after creation, that is, method 2 "page" variable; but method two can only create one preloaded page at the same time;

2. Trigger custom events through mui.fire

Principle: two simultaneous Webviews can use the mui.fire method to trigger custom events in another webview. Therefore, we can create a custom event in the details page and listen to the mui.fire method in the list page.
mui.fire( target , event , data )
target: the webview of the details page (details page preloaded in the list page);
event: the custom event monitored in the details page;
data: Parameters that need to be passed to the details page;

1. Create and listen to the custom event "account_bid_detail_fire" on the details page:

$.plusReady(function() {            /**
             * 实例化获取接口数据方法
             */
            var get_bid_detail = new GET_BID_DETAIL();            window.addEventListener('account_bid_detail_fire', function(event) {                //获得事件参数
                var id = event.detail.id;                    console.log(JSON.stringify(event.detail));                //触发ajax,根据id向服务器请求当前列表详情
                get_bid_detail.init(id);
            });
        });
Copy after login

mui.fire Parameters passed from the list page They are all in event.detail, which can be output for detailed viewing;

2. Trigger the "account_bid_detail_fire" event on the list page:

mui(document.body).on("tap", ".account_bid_list", function() {//触发详情页面的account_bid_detail_fire事件
    var detail_webview = null;    if(!detail_webview) {        //判断webview是否存在
        detail_webview = plus.webview.getWebviewById("account_detail.html");
     }    //detail_webview是在列表页中预加载的页面;
    mui.fire(detail_webview, 'account_bid_detail_fire', {        id: _this.dataset.id
    });    //打开详情页面          
    mui.openWindow({       id: "account_detail.html",//详情页webview的id
       show: {           aniShow: 'none', //页面不显示动画
           duration: '0' //
        }
    });
});
Copy after login

Next, the details can be triggered when the list is clicked on the list page The "account_bid_detail_fire" event of the page, and then trigger the ajax of the details page to update the requested data; Big release of resource collection: https://www.jianshu.com/p/e8197d4d9880

Benefit 2: Full set of detailed video tutorials on getting started with WeChat mini programs and practical implementation: https://www.jianshu.com/p/e8197d4d9880





related suggestion:

Comparison and summary of the differences between mui page jump methods

Example sharing of MUI implementation of pull-up loading and pull-down refresh

mui js Return the method instance code for refreshing the page

The above is the detailed content of How to optimize mui list to jump to details page. 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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

Detailed explanation of whether x220 supports upgrading to Windows 11 Detailed explanation of whether x220 supports upgrading to Windows 11 Dec 27, 2023 pm 11:47 PM

The x220 is a laptop launched by Lenovo in 2012, almost ten years ago. As an old model, many users want to know whether they can upgrade to the latest win11 system. In fact, this computer can be upgraded, but it cannot be upgraded through Microsoft's push method. Can x220 be upgraded to win11: Answer: x220 can be upgraded to win111. Although x220 can be upgraded to win11, the system cannot be upgraded through the methods provided by Microsoft. 2. Because Microsoft has very high hardware configuration requirements for win11 this time, if it is not met, you must use other methods to upgrade. 3. Users who want to upgrade win11 can first download a win11 one-click reinstallation file from this site. 4

How to remove square brackets from a list using Python How to remove square brackets from a list using Python Sep 05, 2023 pm 07:05 PM

Python is a very useful software that can be used for many different purposes depending on the need. Python can be used in web development, data science, machine learning, and many other fields that require automation. It has many different features that help us perform these tasks. Python lists are one of the very useful features of Python. As the name suggests, a list contains all the data you wish to store. It is basically a set of different types of information. Different Ways to Remove Square Brackets Many times, users come across a situation where list items are displayed within square brackets. In this article, we'll detail how to remove these brackets to get a better view of your listing. One of the easiest ways to remove parentheses in strings and replacement functions is in

How to check the authenticity of JBL headphones How to check the authenticity of JBL headphones Dec 29, 2023 pm 10:54 PM

JBL headphones are the first choice for many music listening users, with rave reviews, but everyone is still very afraid of fakes. So how can you check the authenticity of JBL headphones to avoid this problem? Let’s see how to query below. How to check the authenticity of jbl headphones: 1. First enter the "China Product Information Verification Center". 2. Then enter the query code to check whether it is correct and determine whether it is genuine. 3. You can also distinguish it by the clarity of the earphone sound. The sound of genuine headphones is very clear and the sound quality will not change. The sound of counterfeit headphones will have a lot of adulteration, and the sound quality is also very poor. 4. You can turn up the sound of your headphones to the maximum to see if it is harmonious. The sound of real headphones is the same. But the sound of the fake headphones is on

How to count the number of elements in a list using Python's count() function How to count the number of elements in a list using Python's count() function Nov 18, 2023 pm 02:53 PM

How to use Python's count() function to calculate the number of an element in a list requires specific code examples. As a powerful and easy-to-learn programming language, Python provides many built-in functions to handle different data structures. One of them is the count() function, which can be used to count the number of elements in a list. In this article, we will explain how to use the count() function in detail and provide specific code examples. The count() function is a built-in function of Python, used to calculate a certain

Does Bluetooth 5.3 require mobile phone support? For details please see Does Bluetooth 5.3 require mobile phone support? For details please see Jan 14, 2024 pm 04:57 PM

When we buy a mobile phone, we will see that there is a Bluetooth support option in the mobile phone parameters. Sometimes we will encounter a situation where the purchased Bluetooth headset does not match the mobile phone. So does Bluetooth 5.3 need to be supported by the mobile phone? In fact, it is not necessary. Does Bluetooth 5.3 require mobile phone support? Answer: Bluetooth 5.3 requires mobile phone support. However, any mobile phone that supports Bluetooth can be used. 1. Bluetooth is backward compatible, but using the corresponding version requires mobile phone support. 2. For example, if we buy a wireless Bluetooth headset using Bluetooth 5.3. 3. Then, if our mobile phone only supports Bluetooth 5.0, then Bluetooth 5.0 is used when connecting. 4. Therefore, we can still use this mobile phone to connect headphones to listen to music, but the speed is not as good as Bluetooth.

How to Make a Shopping List in the iOS 17 Reminders App on iPhone How to Make a Shopping List in the iOS 17 Reminders App on iPhone Sep 21, 2023 pm 06:41 PM

How to Make a GroceryList on iPhone in iOS17 Creating a GroceryList in the Reminders app is very simple. You just add a list and populate it with your items. The app automatically sorts your items into categories, and you can even work with your partner or flat partner to make a list of what you need to buy from the store. Here are the full steps to do this: Step 1: Turn on iCloud Reminders As strange as it sounds, Apple says you need to enable reminders from iCloud to create a GroceryList on iOS17. Here are the steps for it: Go to the Settings app on your iPhone and tap [your name]. Next, select i

Analysis of frequently asked questions about Cyberpunk 2077 Analysis of frequently asked questions about Cyberpunk 2077 Jan 05, 2024 pm 06:05 PM

Recently, a super popular game Cyberpunk 2077 has been launched online. Many users are rushing to download and experience it. However, there are still many problems in the process. Today we bring you some frequently asked questions about playing Cyberpunk 2077. Come and see if you want anything. Frequently asked questions about playing Cyberpunk 2077: 1. Price details: 1. The purchase price on the steam game platform is: 298 yuan. 2. The purchase price of the epic game platform is: 43 US dollars = 282 yuan. 3. The purchase price of ps4 game terminal is: 400 yuan + HKD and 380 yuan + RMB boxed. 4. The purchase price of Russia in the Russian area is: 172 yuan. 2. Configuration details: 1. Minimum configuration (1080P): GT

Can we insert null value in Java list? Can we insert null value in Java list? Aug 20, 2023 pm 07:01 PM

SolutionYes,Wecaninsertnullvaluestoalisteasilyusingitsadd()method.IncaseofListimplementationdoesnotsupportnullthenitwillthrowNullPointerException.Syntaxbooleanadd(Ee) Appends the specified element to the end of this list. Type parameter E − The runtime type of the element. Parameter e − element to be appended to this list

See all articles