Reputation: 1296
is there a way to get an index of an array within a handlebar template and I want to get the last value in the array and call a . property on it
{{currentRevision.computedRoutingNodes.length-1.numberOfReviewDays}}
computedRoutingNodes is an array of objects
I know i can get an index like
{{currentRevision.computedRoutingNodes.1.numberOfReviewDays}}
but I want to get the last value dynamically
Upvotes: 1
Views: 3201
Reputation: 1590
{{currentRevision.computedRoutingNodes.lastObject.numberOfReviewDays}}
will work if you're using Ember.js.
Upvotes: 1
Reputation: 1401
You could use a helper:
Handlebars.registerHelper('propAtLengthRelativeIndex', function (arr, index, prop) {
return new Handlebars.SafeString(arr[arr.length + ~~index][prop]);
});
And then call it like this:
{{propAtLengthRelativeIndex currentRevision.computedRoutingNodes '-1' 'numberOfReviewDays'}}
Upvotes: 1