Moe
Posts: 0
Joined: Thu Jul 10, 2014 9:24 pm

Find all X and replace with Y and change Color?

I have an array mapped to list grid and the response from my server needs to be tweaked before being displayed. For example: a status code of 2 means that the server is up and status code of 9 means its off.

I so far have used this code:
code
$('#startScreen_statusLabel').each(function() {
var text = $(this).text();
$(this).text(text.replace('9', 'Offline'));
});
$('#startScreen_statusLabel').each(function() {
var text = $(this).text();
$(this).text(text.replace('2', 'Online'));
});
$('#startScreen_statusLabel').each(function() {
var text = $(this).text();
$(this).text(text.replace('4', 'Paused'));
});/code

but its not really working for more than the first instance, I want it to replace all the instances of that number in that specific label. Also, if I wanted the background of the "startScreen_mobilelistitem_64" div to change based on the status is that possible?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Find all X and replace with Y and change Color?

Hi Moe,

That's not good way to do what you want.

You need modify values in "Add JS" section of list mapping.

For example here is a code change value from "9" to "Offline", and change background in accordance to the value:

pre

var collorMapping = {
"9": "#f00",
"2": "#0f0",
"4": "#00f"
};

element.css("background", collorMapping[value]);

var valueMapping = {
"9": "Offline",
"2": "Online",
"4": "Paused"
};

var newValue = valueMapping[value];

return newValue;

/pre

See details where you need to add this code:

http://prntscr.com/49btfr/direct

Regards.

Moe
Posts: 0
Joined: Thu Jul 10, 2014 9:24 pm

Find all X and replace with Y and change Color?

Thanks Yurii - that worked perfectly!!

Vinny B
Posts: 0
Joined: Fri Aug 22, 2014 2:22 pm

Find all X and replace with Y and change Color?

This works great
thanks Yurii

Return to “Issues”