how to add next line \n inside array in widget

servicenow14710
Tera Expert

Hello developers, i have to make two string in diff lines.currently it is in single line liketest1 test2 [ok] but i need

test1[ok]

test2[ok]

* c.data.ip_ok message gives this [ok]

 

  for (var i = 0; i < obj.length; i++) {
            ul = document.getElementById("id");
            temp = null;
            currentItem = obj[i];
alert(currentItem);
            if (currentItem.found == true) {
                errors++;
            }
            temp = document.createElement("li");
            txt = document.createTextNode(currentItem.name + "" + ((currentItem.found == true) ? "[" + data.ip_err + "]" : "[" + c.data.ip_ok + "]"));
            temp.appendChild(txt);
 
 
the above is the code for the same in widget , let me know if anything is required. Thanks!
3 REPLIES 3

The Machine
Kilo Sage

You could try using <br> for HTML instead of '\n' which is Javascript.
var br = document.createElement('br').
temp.appendChild(br);

Hi machine, thanks for the response. yes i tried but couldnt get in the next line.

Please help me how to convert object to array in javascript as the input is taken as

 // for (var i = 0; i < obj.length; i++) //obj- 
If i can convert this to array i might loop each index getting the string in next line. Thanks!

-O-
Kilo Patron
Kilo Patron

The solution is to either place br elements between the lines, or to wrap each text within p or div (or any other element displayed as block).

But in AngularJS HTML is supposed to be defined only in Body HTML template.

One should absolutely not use DOM manipulation, like creating nodes.

While it is "allowed" in link functions, it should be avoided.

 

So the solution needs tinkering both with the Client controller and the Body HTML template.

Example:

  • Body HTML template:
    <div>
    	<p ng-repeat="line in lines">{{ line }}</p>
    </div>​
  • Client controller:
    api.controller = function ($scope) {
    	var c = this;
    
    	$scope.lines = [
    		'Line 1',
    		'Line 2',
    	];
    };​

This results in:13.png