Introduction to JavaScript framework (xmlplus) components (4) list
xmlplus is a JavaScriptframework used for rapid development of front-end and back-end projects. This article mainly introduces the list of xmlplus component design series, which has certain reference value. Interested friends can refer to
List group is an extremely commonly used component. , which must be included in many View component systems. Lists can be made very simple, showing only concise content. Lists can also be made very complex and used to display very rich content.
Component elements
A list cannot be separated from the list items and the container containing the list items. The following is the simplest list component, which contains a list item component Item and a list item container component List.
Item: { xml: "<li id='item'/>" }, List: { xml: "<ul id='list'/>" }
Although this list component is simple, the framework it builds lays the foundation for our continued expansion.
Dynamic operation
The most basic usage of the list component defined above is as follows. This usage is no different from the usage of native list tags. We will make further improvements.
Example: { xml: "<List id='example'>\ <Item>Item 1</Item>\ <Item>Item 2</Item>\ </List>" }
List components generally include three operations: add, delete and modify. For the sake of simplicity, let’s implement these operations first. Since the list items we defined are simple enough, we no longer define a new operation interface here, but use the system interface directly.
Example: { xml: "<p id='example'>\ <List id='list'/>\ <button id='append'>append</button>\ <button id='remove'>remove</button>\ <button id='modify'>modify</button>\ </p>", fun: function (sys, items, opts) { sys.append.on("click", function() { sys.list.append("Item").text("Item 1"); }); sys.remove.on("click", function() { sys.list.first() && sys.list.first().remove(); }); sys.modify.on("click", function() { sys.list.first() && sys.list.first().text("Item 2"); }); } }
This example uses the list's system function append to append the list item, and uses the list item's system function remove to remove the list item. It also uses the list item's system function text to Modify the data of a list item.
Since the above list items contain simple text data, it is appropriate to use the text function to operate on the data in the above example. Now given a list item containing more complex data, the list item additionally defines a data operation interface.
Item: { xml: "<li id='item'>\ <span id='color'>red</span> <span id='shape'>square</span> </li>", fun: function (sys, items, opts) { function getValue() { return {color: sys.color.text(), shape: sys.shape.text()}; } function setValue(obj) { sys.color.text(obj.color); sys.shape.text(obj.shape); } return Object.defineProperty({}, "data", { get: getValue, set: setValue}); } }
The following is an example of a list operation that contains new list items. For adding and deleting components, you can also use the functions provided by the system, but for data acquisition and modification, you can only use the newly defined interface.
Example: { xml: "<p id='example'>\ <List id='list'/>\ <button id='append'>append</button>\ <button id='remove'>remove</button>\ <button id='modify'>modify</button>\ </List>", fun: function (sys, items, opts) { sys.append.on("click", function() { sys.list.append("Item"); }); sys.remove.on("click", function() { sys.list.first() && sys.list.first().remove(); }); sys.modify.on("click", function() { sys.list.first() && items.list.first().data = {color: "blue", shape: "rectangle"}; }); } }
There are no special requirements for the definition of the list item interface. For example, you must use setValue and getValue. This depends on the specific scenario, and you can choose flexibly as needed.
Using third-party list components
Now there are various list components with rich functions on the market, and we can use them through secondary encapsulation. Here we combine the JQuery list component with sorting function to illustrate how to operate.
First encapsulate the list item, because this list item is too long. Pay attention to the data operation interface.
Item: { xml: "<li class='ui-state-default'><span class='ui-icon ui-icon-arrowthick-2-n-s'/><span id='data'/></li>", map: { appendTo: "data" }, fun: function (sys, items, opts) { return { data: sys.data.text }; } }
Secondly, define the container component of the following list items. This container component mainly encapsulates JQuery's list initialization code. Here, the list is defined as sortable but not selectable.
List: { css: "#list{ list-style-type: none; margin: 0; padding: 0; width: 60%; }\ #list li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }\ #list li span { position: absolute; margin-left: -1.3em; }", xml: "<ul id='list'/>", fun: function (sys, items, opts) { var elem = this.elem(); $(elem).sortable(); $(elem).disableSelection(); } }
Finally let’s take a look at how to use the list component. The use of this example is no different from the previous one, but the functionality and performance are quite different.
Example: { xml: "<List id='example'>\ <Item>Item 1</Item>\ <Item>Item 2</Item>\ <Item>Item 3</Item>\ </List>" }
Optimization
If your list has frequent data update requirements, frequent additions and deletions of list items will inevitably occur, which may cause Bad app experience. A feasible optimization plan is given below, which has appeared in the optimization chapter of the official document.
List: { xml: "<ul id='list'/>", fun: function (sys, items, opts) { function setValue(array) { var list = sys.list.children(); for ( var i = 0; i < array.length; i++ ) (list[i] || sys.list.append("Item")).show().text(array[i]); for ( var k = i; k < list.length; k++ ) list[k].hide(); } return Object.defineProperty({}, "value", { set: setValue }); } }
For complex list items, the cost of re-creation is huge. Therefore, this optimization plan reuses existing list items as much as possible, only refreshes data when necessary instead of deleting and rebuilding new list items, and only creates new list items when the existing list items are not enough.
This series of articles is based on the xmlplus framework. If you don’t know much about xmlplus, you can visit www.xmlplus.cn. Detailed getting started documentation is available here.
【Related recommendations】
1. Free js online video tutorial
2. JavaScript Chinese Reference Manual
3. php.cn Dugu Jiujian (3) - JavaScript video tutorial
The above is the detailed content of Introduction to JavaScript framework (xmlplus) components (4) list. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

Many users always encounter some problems when playing some games on win10, such as screen freezes and blurred screens. At this time, we can solve the problem by turning on the directplay function, and the operation method of the function is also Very simple. How to install directplay, the old component of win10 1. Enter "Control Panel" in the search box and open it 2. Select large icons as the viewing method 3. Find "Programs and Features" 4. Click on the left to enable or turn off win functions 5. Select the old version here Just check the box

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

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

Vue is a very popular front-end framework. It provides many tools and functions, such as componentization, data binding, event handling, etc., which can help developers build efficient, flexible and easy-to-maintain Web applications. In this article, I will introduce how to implement a calendar component using Vue. 1. Requirements analysis First, we need to analyze the requirements of this calendar component. A basic calendar should have the following functions: display the calendar page of the current month; support switching to the previous month or next month; support clicking on a certain day,

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

In iOS 17, Apple added a handy little list feature to the Reminders app to help you when you're out shopping for groceries. Read on to learn how to use it and shorten your trip to the store. When you create a list using the new "Grocery" list type (named "Shopping" outside the US), you can enter a variety of food and groceries and have them automatically organized by category. This organization makes it easier to find what you need at the grocery store or while out shopping. Category types available in alerts include Produce, Bread & Cereals, Frozen Foods, Snacks & Candy, Meat, Dairy, Eggs & Cheese, Baked Goods, Baked Goods, Household Products, Personal Care & Wellness, and Wine, Beer & Spirits . The following is created in iOS17

Before discussing the differences, let us first understand what Del and Remove() are in Python lists. Del Keyword in Python List The del keyword in Python is used to delete one or more elements from a List. We can also delete all elements, i.e. delete the entire list. Example of using del keyword to delete elements from a Python list #CreateaListmyList=["Toyota","Benz","Audi","Bentley"]print("List="
