I wonder if you have found out that in the article on Cascade Implementation of ComboBox in easyui
When setting ComboBox, I wrote an onloadsuccess function.
This function is triggered after the remote data is loaded successfully. It can be divided into the following situations:
1. If it is not limited by onbeforeload, it will be triggered once during initialization regardless of the method used, because onbeforeload will be triggered once in any case during initialization.
2. If it is not restricted by onbeforeload, when data is loaded in remote mode, each request is triggered once the data is successfully received.
The onloadsuccess function I wrote previously aims to trigger onloadsuccess to load and translate the cascade ComboBox values when the primary ComboBox loads data and translates the data.
Because the cascade ComboBox is completely passive, we trigger it in the onselect function when we create a new one, and onloadsuccess is required for modification.
Let's take a look at my previous statements:
onLoadSuccess:function(){ var value = $(this).combobox('getValue'); if(value != ''){ <span style="white-space:pre"></span>$('[comboname=city]').combobox('reload', 'test/getCityListByProvince?id=' + $(this).combobox('getValue')); } }
Here, we first determine whether there is a value in the main ComboBox. If there is a value, we load the data in the cascade ComboBox for translation.
Is there any problem?
This does not seem to be a problem for the drop-down selection box of Editable: false, because the value must be the corresponding value instead of the other mess.
However, if the prompt function of ComboBox is implemented like in the previous article, it seems that there are some problems.
For example, when we enter a keyword, each keyword will trigger onloadsuccess, and the value also has a value, and that is the value you entered (but here I personally feel that the design of ComboBox is a bit problematic, because the input value should be used as text, and the value should be blank before the Select Operation)
In this way, there will be many more incorrect requests, because the cascade request only needs to be triggered during onselect.
So how can we improve it? Add a judgment condition.
Solution 1: If ($ (this). ComboBox ('getvalue') =$ (this). ComboBox ('gettext') {return}
It seems feasible, but in fact, when the input speed is too fast, the two values will be different! The reason is not further explored. Give up.
Solution 2: because the values used here are numbers, you can use a regular expression to determine
If (/^ \ D + $ /. test (value). This method is feasible for the moment, but not perfect. When a user enters a number, it triggers a keyword search, so no result is obtained.
Solution 3: onbeforeload can be used to determine
Onbeforeload: function (PARAM) {If (Param = NULL | Param. Q = NULL | Param. q. replace (// G, '') ='') {VaR value = $ (this ). comboBox ('getvalue'); If (value) {// here it can be determined to be modified, where the data Param in the cascade ComboBox is loaded. id = value; return true;} return false ;}}
Both solution 2 and solution 3 can achieve the goal ~
ComboBox -- onloadsuccess usage example