The results of pre-modification kindeditor support file uploads returned

Today, we say the problem is likely that most people think is not a problem. However, since met, record it.

Imagine a scenario, the system has an interface that is used to upload pictures, will return after a successful upload images and final results stored address images, such as to return the following results: {status: 1, imgUrl: 'xxxx'}. Used kindeditor know its return requirement is the result of the format {error: 0, url: 'xxxx'}, if you want to reuse existing upload interface, you have to rewrite kindeditor. In fact, it is also easy to change, find the following section of code in the source code kindeditor-all.js:

was uploadbutton = K.uploadbutton ({
button : K('.ke-upload-button', div)[0],
fieldName : filePostName,
Form: (b. In-form ', Div)
target : target,
width: 60,
afterUpload : function(data) {
dialog.hideLoading ();
if (data.error === 0) {
var url = data.url;


In front if (data.error === 0) was added to a pretreated you return logic value. Suppose I put this method is called here parseOfUploadImg, so my code would look like this:

was uploadbutton = K.uploadbutton ({
button : K('.ke-upload-button', div)[0],
fieldName : filePostName,
Form: (b. In-form ', Div)
target : target,
width: 60,
afterUpload : function(data) {
dialog.hideLoading ();
if(self.parseOfUploadImg){
data = self.parseOfUploadImg.call(self,data);
}
if (data.error === 0) {
var url = data.url;

ok, I have been changing for the better, just write parseOfUploadImg in options when creating rich text box when using such a function is used to return the results of such pre-processing:

{

....

parseOfUploadImg:function(data){

return {error:data.status,url:data.imgUrl};

}


....

}


It's done :)


Published 55 original articles · won praise 39 · views 80000 +

Guess you like

Origin blog.csdn.net/Chinese521/article/details/52329343
Recommended