我正在尝试制作用于Meteor客户端的分页功能.因此,我需要知道服务器上的记录数.
在服务器上(在server/bootstrap.coffee中)我有这个代码:
Meteor.methods
ContactsCount: ->
Contacts.find().count()
console.log("Totalrecords: " + Contacts.find().count())
Run Code Online (Sandbox Code Playgroud)
调用服务器部分(它在控制台上显示正确的数字 - 40)
在客户端我有:
$.extend Template.pager,
GetRecordCount: ->
Meteor.call("ContactsCount", (error,result) ->
console.log('r', result)
Run Code Online (Sandbox Code Playgroud)
从浏览器控制台Template.pager.RecordCount()返回
undefined
r 30
我理解'undefined'是从Template.pager.RecordCount()返回的,它首先返回.
当结果可用时,它将显示在控制台中.
但是如何在寻呼机模板中获得结果的值?
我现在正在搜索Java回调几个小时,但无论我尝试什么,我都无法让它工作.
请帮忙.
这是一个更新.
我看了无效的文档.但这个例子对我没什么帮助.在函数调用中使用参数在客户端中设置温度.所以没有使用回调.回调是我的问题.
我这样解决了:
Meteor.call("ContactsCount", myFunc)
### This is the call back function when the server
function 'Meteor.call("ContactsCount", myFunc)' is called
When the result from the server call is returned, this will be executed ###
myFunc = (error, result) ->
if !error
pages = result / Session.get("page_size")
Session.set "total_pages", …Run Code Online (Sandbox Code Playgroud)