1

i have got here this little code snipped:

$(document).ready(function () {
$('td').each(function(index) {
    thisValue = "";                                     //Variable leeren
                                                    //alert(index + ': ' + $(this).attr("id"));
    currentField = $(this).attr("tid");
                                                    //alert (currentField);
    currentID = $(this).attr("ftn");
                                                    //alert (currentID);
    $SP().list(TableName).get({
        fields: currentField,
        where:"ID = "+currentID
    },function getData(row) {
        console.log (row[0].getAttribute(currentField) *1);
        thisValue = (row[0].getAttribute(currentField) *1);
        $(this).text(thisValue);                    // Wert der Listenzelle in die HTML Tabelle schreiben
    })

});

it is working fine and if i do a console.log the value for each searched cell element is showing up in the console. But actually i'm not able to bring those Values into the page i think its that because the $(this) is not longer "connected" to the tablecell in the html page i think. here is my HTML Construct:

<div class="uk-panel uk-panel-box uk-panel-box-muted">
                                    <h4>Product 1</h4>
                                    <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">
                                        <tr><th>Service Requests:</th>  <td tid="product1" ftn="1" id="sr_acvl">NULL</td></tr>
                                        <tr><th>ITSM Tickets:</th>      <td tid="product1" ftn="2" id="tt_acvl">NULL</td></tr>
                                        <tr><th>E-Mails:</th>           <td tid="product1" ftn="3" id="em_acvl">NULL</td></tr>
                                        <tr><th>Anrufe:</th>            <td tid="product1" ftn="4" id="ca_acvl">NULL</td></tr>
                                        <tr><th>Skype &amp; Other:</th> <td tid="product1" ftn="5" id="sk_acvl">NULL</td></tr>
                                    </table>
                                </div>

what do you think? i think its only one little smart thing but i did not see any solution yet...

BtW. i am Using sharepointplus from here: http://aymkdn.github.io/SharepointPlus/symbols/$SP%28%29.list.html

kind regards Proximate

Marco
  • 473
  • 5
  • 21

1 Answers1

3

Simply store the context reference inside a variable for later use:

$(document).ready(function () {
$('td').each(function(index) {
    var self = $(this);  //  <----- this is the key
    thisValue = "";                                     
    currentField = self.attr("tid");
    currentID = self.attr("ftn");

    $SP().list(TableName).get({
        fields: currentField,
        where:"ID = "+currentID
    },function getData(row) {
        console.log (row[0].getAttribute(currentField) *1);
        thisValue = (row[0].getAttribute(currentField) *1);
        self.text(thisValue);
    })

});
Shomz
  • 37,421
  • 4
  • 57
  • 85
  • nice its working thx! :-) one thing left - i use multiple html tables to display each product (around 10) - if i build it like you written above every turn replaces the contents of the table before with zero. that means it works if i use just 1 table but if i add a second table with elements attribute tid="product2" the each overrides the first with zeros. any idea why that happend? thanks again – Marco Feb 11 '16 at 14:41
  • You're welcome! :) Hmmm, perhaps you could run .each separately for every table or at least do some checks to make sure you're only editing the table with the proper `tid`. Sorry, I'm not familiar with sharepointplus, so I can't give you a more accurate solution without seeing it in action. – Shomz Feb 11 '16 at 14:45
  • 1
    its ok :) - i try to figure that out my first idea was also to rewrite it for every tid thanks! – Marco Feb 11 '16 at 14:53