jquery $.each syntax check?

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Can someone give me a quick thumbs up/down on my syntax?
var $ = skuid.$;
var mSTD = skuid.$M('STDTest');

$.each(mSTD, function(i, row){
value += row.STD__c + ' (' + row.Results__c + ') '; });

If my model STDTest has two rows:
Row 0 has STD__c: HSV1, Results: Negative
Row 1 has STD__c: HIV, Results: Positive

I'm trying to produce a text variable 'value' that would look like:
'HSV1 (Negative) HIV (Positive) '

Am I understanding the way $.each works?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Your mSTD variable is a reference to the model object.  So your code as is would iterate over the properties of the model.  This is most likely not your intention.  You should iterate over mSTD.data instead.

$.each(mSTD.data, function(i, row){
    value += row.STD__c + ' (' + row.Results__c + ') ';
});
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Thanks, Ben!