[英]Meteor: Best Method for Passing Mongo Selector from Client to Server
[英]passing value server to client in method meteor
客戶端代碼
Template.hello.events({
"click": function () {
Meteor.call('Message',function(result){
alert(result);
});
服務器端方法調用
if (Meteor.isServer) {
Meteor.methods({
'Message':function(){
SerialPort.list(function (err, ports) {
ports.forEach(function(port) {
console.log(port.comName);
var atxt = port.comName;
return atxt ;
});//ports end
}); //list end
} //message end
}); //method end
} //server end
上述程序'undefined'打印警報框客戶端。 return atxt沒有返回任何值。 請幫幫我meteor apllication傳遞服務器端返回值訪問客戶端!!!
當Meteor server side
方法返回一些數據時,客戶端需要通過回調asynchronously
獲取。 在該回調中,需要有兩個參數, error and result
。 基本上第二個參數是你的結果,第一個參數是error
(如果有的話)。 因此,您需要相應地更新客戶端代碼。 除了從服務器端返回之前,只需console.log
您的數據,以便您可以確定結果。
Meteor.call('Message',function(err,result){
if(!err) {
alert(result);
} else {console.log(err);}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.