I'm using jquery tabs in my code. I need to call $('ul.tabs').tabs(); after once the HTML is rendered. But this is throwing error "Type : d[0] is undefined". The code which is used is below.
<template name="customersMapping">
<div class="col s9 blue-grey lighten-5" id="side-right">
<div class="row">
<div class="col s12">
<ul class="tabs" id="usersMappingTab">
{{#each customerClientMapping}}
<li class="tab col s2"><a href="#{{_id}}_Tab">{{name}}</a></li>
{{/each}}
</ul>
</div>
{{#each customerClientMapping}}
<div id="{{_id}}_Tab" class="col s12">
{{#each userChats ..}}
<div>{{name}}: {{message}}</div>
{{/each}}
</div>
{{/each}}
</div>
</div>
In client.js
Template.customersMapping.rendered = function() {
if ($('#usersMappingTab').length > 0) {
$('ul.tabs').tabs();
}
};
Template.customersMapping.helpers({
'customerClientMapping' : function() {
return UserChatsMapping.find({cid : Meteor.userId()}, {sort: {time: -1}});
},
'userChats' : function() {
return Messages.find({uid:this.uid}, {sort:{time: -1}});
}
});
I think the jquery function is called before the HTML is rendered. Please let me know how to fix this.
I have divided into two template, one for managing subscriptions, and other for rendering tabs.
In the first template(customersMapping) we wait subscriptions to be ready.
When they are ready we can render our second template(tabs).
In tabs template's onRendered callback we can call jquery ui's tabs method without delaying the execution, because our data is already transferred to the client.