The setvalue Method for Solving easyui combotree is invalid.

Source: Internet
Author: User

When I was writing code today, I encountered a very strange problem:

$ ('# Department_parent'). combotree ('setvalue', row. ID );

 AjaxForProvince(); $(‘#province‘).combobox(‘setValue‘, row.province_id); AjaxForCity(row.province_id); $(‘#city‘).combobox(‘setValue‘, row.city_id); AjaxForZone(row.city_id); $(‘#zone‘).combobox(‘setValue‘, row.zone_id); AjaxForDepartment(row.zone_id); $(‘#department_parent‘).combotree(‘setValue‘, row.id);

The above logic is very simple, that is, to load provinces, cities, and counties on the page, load province and county levels, load province levels, and load departments.

But the problem is that when I click, the province, city, county, and region levels can be loaded normally, but when I load the data to combotree, the box will be blank after the correct value is flashed.

At that time, I had no idea what the problem was. I did not see this situation in my online search. Even if you try to change row. ID to a common number, it still does not work.

Since there is no foresight, you can only analyze it yourself.

Since the combotree correctly loads the drop-down list during loading, the ajaxfordepartment method is called successfully.

But when it is loaded to setvalue, it will flash and disappear. It indicates that the problem lies here. It is likely to be related to the loading sequence or loading duration.

Why?

Javascript execution is a single thread, but we cannot know the execution sequence within the combotree, so it is very likely that

$ ('# Department_parent'). combotree ('setvalue', row. ID );

First, and

Ajaxfordepartment (row. zone_id); will be executed later, which will cause the above problems.

With a try, change the Code as follows:

 AjaxForProvince(); $(‘#province‘).combobox(‘setValue‘, row.province_id); AjaxForCity(row.province_id); $(‘#city‘).combobox(‘setValue‘, row.city_id); AjaxForZone(row.city_id); $(‘#zone‘).combobox(‘setValue‘, row.zone_id); AjaxForDepartment(row.zone_id); setTimeout(function () { setTreeValue(row) }, 300);   var setTreeValue = function (row) {         $(‘#department_parent‘).combotree(‘setValue‘, row.id);     }

Then run. Everything is normal.

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.