I’m attempting to loop through the rows in a model I have in javascript. Here is the code I’m running:
var params = argumentse0], $ = skuid.$;
console.log(‘Oh Yeah!!!’);
var modelStuff = skuid.model.getModel(‘modelName’);
console.log(modelStuff);
$.each(modelStuff.data,function(i,row) {
console.log(‘Oh No!!!’);
});
console.log(modelStuff);
Both of my console.log(modelStuff) calls before and after the loop show that the model has two rows with data, but I never get ‘Oh No!!!’
This is basically copy pasta straight from an example found in another question here. How can I show data (2 rows to be exact) in both of my console.logs but not ever execute the loop on modelStuff.data…
Also, if I run modelStuff.getRows() it returns an empty array…
Hi Jerry,
It looks like the weird logging behavior that you’re seeing is because of how your browser’s console works. In reality, at the time your code runs, the model has no rows. When you log a reference to the model, Chrome’s console is actually showing you the state of the model at a later time.
How is that snippet being invoked? Is it part of a row action?
Thanks Ben, and yes. The snippet I’m running gets called when things are added to that model. I’ve actually gotten past this and was just about to update this question.
I solved my problem by wrapping the whole thing in one of these guys:
$.when(modelStuff.updateData()).then(function(){
things and stuff;
});
Not sure how to mark a question solved though…
Glad you figured it out. Actually, you don’t actually need to use $.when() in this case. Since updateData() returns a promise, you should be able to just use the code below…
modelStuff.updateData().then(function(){ //things and stuff; });
Cool, I’ll give that a try.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.