looping over the rows in a model

  • 1
  • Question
  • Updated 5 years ago
  • Answered
in order to compose a complex report I'm addressing 2 models.... one gives me a count of client encounters for each client

the next is the actual list of encounters for a given time period.
I'm using a for loop to loop over the list of encounters.
I suspect there is an $.each idiom i could use... but i could not find an example in the api sample code

is there a method, or a way to loop over the data in a model directly ?

var params = arguments[0]
$ = skuid.$;
// get the data from the first tab
counts = skuid.model.getModel('HH_Client_Counts').data;
// build an array holding the ids of the clients that have had more than 1 service
returns = ['0000'];
for(var current_client=0; current_client 1){
// get the model for this tab, because we will need to use its methods
encounters = skuid.model.getModel('HH_Client_Encounters');
// get the data portion of the model
encounter_data = encounters.data;
var row = '';
var last_date = '';
var update_value = 0;
var old_client_id = '';
var client_id=0;
var set_selected = false;

// loop over the data
for(var current_row=0; current_row 1){
update_value = 1;
else {
update_value = 0;
// console.log('==selected ==' + set_selected + '=new====' + client_id + '==old==' + old_client_id);
// reset the variable for the next pass
old_client_id = client_id;

} // for current_row
Photo of ktyler


  • 9,274 Points 5k badge 2x thumb

Posted 5 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
I actually got this syntax from the skuid.model documentation, found here 
in the code at the end of the page. The basic syntax is like so:
  1. $.each(myModel.data,function(i,row){
  2. myModel.updateRow(row,myfield, myValue);
  3. });

Photo of John Nelson

John Nelson, Product Manager

  • 3,304 Points 3k badge 2x thumb
Yep, Moshe's right on. jQuery's generic $.each is what you'll want to use.