简体   繁体   中英

How to add text to element using Jquery?

Coming back to jquery after long time trying to add text to text area , with the below logic i dont see text at the level i am trying to put in html. what would be correct approach to get expected result ?

main.js


    function updateRequest(ref, version) {
        if (SDKresult[ref]) {
            if (SDKresult[ref].request) {
                delete SDKresult[ref].request.env;
                SDKresult[ref].request['nodeEnv'] = SDKresult['nodeEnv'];
                SDKresult[ref]['app'] = "require['/wrapper-sdk']";
            }

            $('#request_method_JS').text(ref + '(' + JSON.stringify(SDKresult[ref].request, null, 4) + ', function(result) {\n //Your code goes here \n debugger; \n console.log(result); \n});');
        }
    }

main.html

 <pre id="request_method_JS" style="margin: 5px;"></pre>

current Result

App.Member.Details({
    "apiKey": "769c71dfa4ef3",
    "tokenId": "587218f552"
}, function(result) {
 //Your code goes here 
 debugger; 
 console.log(result); 
});

Expected output in textArea should be

var app = require('/wrapper-sdk');

app.Api.setConfig({
            "env": "DEV"
        });

App.Member.Details({
    "apiKey": "769c71dfa4ef3",
    "tokenId": "587218f552"
}, function(result) {
 //Your code goes here 
 debugger; 
 console.log(result); 
});

Put everything you want to write into a variable, then call .text() with that.

function updateRequest(ref, version) {
    if (SDKresult[ref]) {
        if (SDKresult[ref].request) {
            delete SDKresult[ref].request.env;
            SDKresult[ref].request['nodeEnv'] = SDKresult['nodeEnv'];
            SDKresult[ref]['app'] = "require('/wrapper-sdk')";
        }

        var text = '';
        text += 'var ref = ' + SDKresult[ref].app + ';\n\n';
        text += 'app.Api.setConfig({\n    "env": "DEV"\n});\n\n';
        text += ref + '(' + JSON.stringify(SDKresult[ref].request, null, 4) + ', function(result) {\n //Your code goes here \n debugger; \n console.log(result); \n});';
        $('#request_method_JS').text(text);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM