Baidu Editor takes values from the Json object to complete the first rendering and draws a table in the editor.

Source: Internet
Author: User

The first time I started enterprise-level applications, I felt that the logic must be very clear and there are many different concepts.
In the Baidu Editor, how does one complete the value of the slave server to render the table? Console is required. log (editor); in the official API, we have already told you that the write method is setContent (). Here, as long as we can input the final string, We can initialize it, draw any desired node.
After sending () is complete, onreadystatechange = function () {} begins with the previous AJAX code. This section of AJAX is compatible with the browser, and has been learned from Nicolas's book. Copy codeThe Code is as follows: function AJAX (){
If (typeof XMLHttpRequest! = "Undefined "){
Return new XMLHttpRequest ();
} Else if (typeof ActiveXObject! = "Undefined "){
If (typeof arguments. callee. activeXString! = "String "){
Var versions = ["MSXML2.XMLHttp. 6.0", "MSXML2.XMLHttp. 3.0", "MSXML2.XMLHttp"];
For (var I = 0, len = versions. length; I <len; I ++ ){
Try {
Var xhr = new ActiveXObject (versions [I]);
Arguments. callee. activeXString = versions [I];
Return xhr;
} Catch (ex ){
}
}
}
Return new ActiveXObject (arguments. callee. activeXString );
} Else {
Throw new Error ("Error ");
}
}

In the JSON dataset, we know that this is a pair of key values. When we get a Json object from the server, we need to parse it and then generate the DOM node we need. For example, the following is a JSON dataset.Copy codeThe Code is as follows :{
"Head ":{
"Rows": 3,
"Cells": 2
},
"Body ":{
"Rows": 3,
"Cells": 2
}
}

Next, the obtained data is stored in responseText. Therefore, you need to set a variable to accept it, So var a = eval ("(" + xhr. responseText + ")"); in this step, the entire Json object is retrieved from the server. Then for in, you can obtain the data stored in the Json object.Copy codeThe Code is as follows: for (var B in ){
Console. log (a [B]. rows );
}
// For in traverses the Json object, and B gets the key value.

After obtaining the specific JSON dataset, you can use + = to spell the node string, use + = to spell the node string, from top to bottom, judge, and loop, you only need to set an empty variable at the beginning to receive all of this.
In the last step, editor. setContent (Json) is used to initialize the editing area of the editor and render the node from the server.
Industry is superior to diligence, and it is not suitable for industry. Think about things and get rid of things. The growth of newcomers lies in summary. All articles and examples are self-summary only for learning and communication.

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.