Page 1 of 1

Append a string to a listitem

Posted: Sun Apr 05, 2015 10:53 pm
by xman

I have a complex service which runs and then returns a string value from the the DB. I want the result of this service to append the string to an already existing listitem on the page.

This listitem is already populated to some extend by other service, I cannot really just run current service over it (as it will overwrite the results). To summarize my problem is to:

  1. Find the last element in the already existing list.
  2. Append the new value after this element.

Append a string to a listitem

Posted: Mon Apr 06, 2015 5:23 pm
by Egor Kotov6832188

Hello,

1) On Success event add js code
2) in this code
a) with jquery selector find you target item
b) set value
in data variable you will have your new value


Append a string to a listitem

Posted: Mon Apr 06, 2015 5:25 pm
by xman

Hi Egor,

I am not an expert in JS, and so will need a little more help here. How to do I find my listitem using JS and assign value? ...appreciated.


Append a string to a listitem

Posted: Tue Apr 07, 2015 11:19 pm
by Yurii Orishchuk

Hi Xman,

Here is example of code to change last listitem component text with some value postfix:

precode

//Here you need to use your value from service.
var textToAdd = "_someValueToAdd&quot

//Where "mobilelist_47" is your goal list component name.
var textElement = jQuery('[name="mobilelist_47"] :not(li[data-appery-tpl="true"]) [name="mobilelistitem_48"]:last h3')
textElement.text(textElement.text() + textToAdd);

/code/pre

Regards.


Append a string to a listitem

Posted: Tue Jan 26, 2016 7:34 am
by Amirul Momenin

How to set multiple value with jquery
Apperyio("mobilelistitem_comany").text("A");
Apperyio("mobilelistitem_comany").text("B");

I need in this way


Append a string to a listitem

Posted: Fri Jan 29, 2016 10:34 am
by Evgene Karachevtsev

Hello Amirul,

You can do it 2 different ways:
1) Like the last answer from Yurii
preElement.text(Element.text() + additionalText)/pre
2) Or if you want to append multiple values just first concatenate them into one variable and then append to element
prevar dataToAppend = "A" + "b" + .. whatever value;
Element.text(dataToAppend);/pre