Delete element of JS array -- The jquery easyui tab component does not provide a solution to delete Element

Source: Internet
Author: User

 

I used the tab component of jquery easyui today. I found it useful to see the demo.

The demo provides three methods:

Addtab ()
Getselected ()
Update ()

One problem I encountered during development is that the tab component has a cross sign in the upper right corner to close the tab,

However, it does not provide a method for deleting a tab, that is, it encapsulates the method for deleting a tab.

(When you open a tab page and click open again, you will be prompted that it has been opened, rather than opening the same tab,

Otherwise it will be opened again, so I need to record the opened tab when opening the tab and delete it from the record when closing the tab,

In this way, I can ensure that only one tab can be opened once. Do not display it repeatedly)

This is probably the biggest headache for all developers. You have encapsulated it, and I really need this method, so I cannot study your source code?

 

If the source code is very large, it will take more time to study more than 500 lines.

I chose another method.

I can declare an array. When adding a tab page, add the ID of this tab to the array.

When the next page is not closed and the user clicks the next tab, I first process this array and cyclically find whether each ID exists,

(If this tab does not exist, this tab is disabled and this ID is deleted from the array)

If this element exists, it indicates that the tab has been opened on the page. Do not open it again. You must prompt that the tab has been opened.

 

Look at the Code:

 

VaR isshow = new array (); function validateshow () {for (VAR I = 0; I <isshow. length; I ++) {var temp = isshow [I]; If (document. getelementbyid (temp) {} else {isshow. splice (I, 1) ;}} function isexisttab (ID) {validateshow (); var falg = false; For (VAR I = 0; I <isshow. length; I ++) {var temp = isshow [I]; If (temp = ID) {falg = true ;}else {falg = false ;}} return falg ;} function createtab (ID, PID, name, URL) {// alert (ID + PID + name + "jjj" + URL ); // alert ("here --" + ID + "--" + PID + "--" + name); If (isexisttab (ID )) {alert ("This page has already opened");} else {$ ('# page2 '). tabs ('add', {Title: name, content: '<Div Title = \ "' + name + '\" id = \ "' + ID + '\" closable = "true" style = "overflow: hidden; width: 100%; Height: 100%; "\> <IFRAME scrolling =" yes "frameborder =" 0 "src =" '+ URL +' "style =" width: 100%; height: 100%; "> </iframe> </div> ', iconcls: 'icon-save', closable: true}); isshow. push (ID );}//////}

 

Here I want to talk about how to delete elements from arrays in JS. splice (I, 1 );

Arrayobj. splice (deletepos, deletecount); // deletes the specified number of deletecount elements starting from deletepos in the specified position. The removed elements are returned in the array format.

If we traverse in for, delete the current element as. splice (I, 1 );

I have never used the delete method before. Today, I checked that JS does not have the Remove Method for deleting elements from arrays !!!

I'm surprised, but I can. splice (I, 1); write a blog record here to achieve the same effect.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.