简体   繁体   中英

Paging with WebSockets in Sails

I have an existing web app with an ExtJS front end and Sails back end. Currently the app uses XHR for data interchange but I wish to switch to Websockets.

Reading the Sails Docs it says that a call to io.socket.get will subscribe the client to the returned set of records. When paging however I'm only interested in receiving server-sent events for the current page of records.

Is there some means of unsubscribing records as the user pages?

io.socket.get() will only subscribe you if you are using the Blueprint API of sails. That being said have a look at find where and set the limit and skip properties accordingly. So you will only be subsribed to the instances which are queried.

var page = currentPage;
var amount = 30;

io.socket.get('/entry?skip=' + page * amount + '&limit=' + amount, function (entries) {});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM