Nested Spacebars


#1

I need help with nested Spacebars. So I have a helper below:

UI.registerHelper('scheduleDates', function (inc) {
  var dateArray = [];
  for (var i = 0; i < 7; i++) {
    dateArray[i] ={
      'dateValue': moment().day(i+7+inc).startOf('day'),
      'formId': "formId"+i,
    }
  };
  return dateArray;
});

It works fine when inc is set to 0. However, when it changes to 7 that’s when the dateValue starts skipping by month, and I can’t figure out why…

I have a drop down in my template. When that dropdown changes value, the value of inc changes based on a session variable. The value of inc can either be 0 or 7. Here is how my spacebars in my template look like:

  {{#each scheduleDates inc}}
    {{> scheduleDay}}
  {{/each}}

I print out the value of inc and it correctly prints out 0 or 7 depending on what’s selected in the dropdown menu. According to the documentation on Spacebars, I don’t know why this doesn’t work and I could really use some help on figuring this out.

I don’t get any errors in this code. I just get the wrong output.


#2

update code to this

console.log(inc);
console.log(dateArray);
return dateArray;

and paste console output


#3

It seems to be setting itself as expected but the value of i is even correct…I don’t understand what’s going on.

  0
    helpers.js?4b1b8e53ea678ccddc10ab2a60c415a173bbd590:34 [Object, Object, Object, Object, Object, Object, Object]0: ObjectdateValue: Moment_d: Sun Aug 16 2015 00:00:00 GMT-0500 (CDT)_isAMomentObject: true_isUTC: false_isValid: true_locale: Locale_pf: Object__proto__: MomentformId: "formId0"__proto__: Object1: Object2: Object3: ObjectdateValue: Moment_d: Wed Aug 19 2015 00:00:00 GMT-0500 (CDT)_isAMomentObject: true_isUTC: false_isValid: true_locale: Locale_pf: Object__proto__: MomentformId: "formId3"__proto__: Object4: Object5: Object6: Objectlength: 7__proto__: Array[0]
    helpers.js?4b1b8e53ea678ccddc10ab2a60c415a173bbd590:33 7
    helpers.js?4b1b8e53ea678ccddc10ab2a60c415a173bbd590:34 [Object, Object, Object, Object, Object, Object, Object]0: ObjectdateValue: Moment_d: Sun Oct 25 2015 00:00:00 GMT-0500 (CDT)_isAMomentObject: true_isUTC: false_isValid: true_locale: Locale_pf: Object__proto__: MomentformId: "formId0"__proto__: Object1: Object2: Object3: Object4: Object5: Object6: Objectlength: 7__proto__: Array[0]

#4

I added inc = parseInt(inc); and it now works. For whatever reason it though that int was a string rather than an integer. Is there a better way to do this?