Baidu editor from the JSON object value, complete the first rendering, in the editor inside the table _ page Editor

Source: Internet
Author: User
The first time you do enterprise-class applications, feel a little: the logic must be very clear, and have a lot of different concepts.
In the Baidu editor, how to complete the value from the server, to render the table? Here we need to console.log (editor), and the official API has told us that the way to write is SetContent (), where we can simply pass in the string that we finally spelled, that we can draw any node we want in the initialization.
After the Send () is complete, onreadystatechange = function () {}, preceded by an AJAX code. This Ajax is the elimination of browser compatibility, learned from Nicholas's book.
Copy Code code 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 value data sets. When we take the JSON object from the server, we start parsing it and then generating the DOM node that we need. For example, the following pair of JSON datasets.
Copy Code code as follows:

{
"Head": {
"Rows": 3,
"Cells": 2
},
"Body": {
"Rows": 3,
"Cells": 2
}
}

Next, the data we get is stored in the responsetext, so we also need to set a variable to accept, so var a = eval ("+xhr.responsetext+")); At this point, our entire JSON object, Was taken from the service side. Then for in it, you can fetch the data stored in the JSON object.
Copy Code code as follows:

for (Var b in a) {
Console.log (a[b].rows);
}
For in traversal of the JSON object, B is the key value has been taken.

After you get the specific JSON dataset, you can spell the string of nodes by + = to spell it with + +, from top to bottom, to judge, to loop, all you need to do is set an empty variable at the beginning to receive it all.
The final step, Editor.setcontent (Json), is that the editor can edit the initialization of the region, take values from the server, and render the nodes.
Diligence is a waste of leisure. Hua Xintong, ruined by the following. The growth of new people, is summed up. All articles and examples are only self summarized and are 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.