I’m trying to use jScrollPane with meteor.js, but it’s not behaving as expected. First off, if I give the ‘.scroll-pane’ class to a div, it will work without being initialized explicitly by me. But when I try to initialize it explicitly, it does not work. Is this some sort of meteor magic? or I am missing something obvious.
Second, if I don’t initialize it, but I try to access it…it’s data is empty, so I can’t use the api on it. I’ve included some sample code below, please let me know if I am doing something wrong.
html
...
<div class="rectangle">
<div class="chat scroll-pane" id="chatWindow">
{{#each Messages}}
{{#if Compare uId UID}}
<div class="bubble me">{{Text}}</div>
{{else}}
<div class="bubble you">{{Text}}</div>
{{/if}}
{{/each}}
</div>
<input class="textinput" type="text" placeholder="Insert Message" id="textToSubmit">
<button class="btn btn-success" id="submit" autofocus="autofocus">Send
<br>
<br>
</button>
</div>
js
if (Meteor.isClient) {
...
var Message = new Meteor.Collection("Message");
Template.Message.rendered = function(){
if(!this._rendered) {
this._rendered = true;
var scroll = $(this.find("#chatWindow"));
var api = scroll.data('jsp');
console.log(api);
}
};
...
}
If you need any more info, please let me know.
Thanks
There are a couple things going on:
(1) you need to wire up the reactivity to your template to ensure that the timing of the incoming
Messagesis correct. This is achieved by using aSessionvariable to set the load, and by settingTemplate.scroll.Messagesequal to a function that returns a collection cursor. Typically, you would not need to set a Session this way if yourTemplate.scroll.Messagesreturns a query that uses aSessionobject (i.e., a roomId). If that were the case, you could forgo the callback on theMeteor.subscribecall and the “loaded”Sessionaltogether.(2) you’ll want to turn off
autopublish(meteor remove autopublish) and explicitly subscribe to the data so you know when your collection loads;(3) you must declare your messages
Collectionoutside theisClientblock to ensure the server knows about it.HTML:
JS: