Easyui ComboBox drop-down box initializes default values and methods that keep the value displayed all the time

Source: Internet
Author: User

Easyui ComboBox drop-down box The default initial value is NULL, the following is the way to initialize the default value after loading the data remotely, and to keep the value in the top of the drop-down box.

The current requirement is to add the "All Databases" field at the time of initialization, and at the drop-down, the "all Databases" is at the top of the line.

The effect of initialization is as follows:

The following drop-down effects are as follows:

Implementation method:

The Easyui ComboBox has a loader property, and the Easyui API describes the loader attribute as follows:

The Easyui ComboBox has a onloadsuccess event, and the Easyui API describes the Onloadsuccess event as follows:

The implementation method is to utilize the loader attribute and onloadsuccess event of Easyui.

The complete code looks like this (please focus on the key code, the part that is highlighted in red):

<input id= "DBName" name= "DBName" class= "Easyui-combobox" style= "width:200px"Data-options= "Valuefield: ' dbname ', TextField: ' dbname ', Editable:false,loader:function (param,success,error) {$.ajax ({url: ' ${pagecontext.request.contextpath}/rds/rds_findrdsdatabase                                                  S.action?dbinstanceid=${param.dbinstanceid} ', DataType: ' JSON ', Success:function (data) {Data.rows.unshift ({dbname: ', dbname: ' All Databases '});                                                success (data.rows);//loader Success}                                             }); },Onloadsuccess:function () {$ (' #dBName '). ComboBox (' SetValue ', ' all databases '); }                                        "/>

The above method Unshift () adds one or more elements to the head of the array, and then moves the existing elements to a larger position of the subscript to make room, which returns the new length of the array.

Easyui ComboBox drop-down box initializes default values and methods that keep the value displayed all the time

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.