我在我的項目之一,我需要簡單地顯示流星模板上的數據說inventory.html使用流星。我在服務器端有一個方法,它可以查詢並從mongoDb獲取數據。我從客戶端調用服務器端方法,並獲取客戶端的所有數據,但隨着數據傳到客戶端需要一段時間模板呈現沒有任何值的平均時間,所以我將如何顯示值模板或有任何技術,以便我可以顯示我的價值觀或數據。如何渲染數據來自服務器端(數據庫調用)流星方法模板流星
目前我正在使用服務來設置和獲取數據,即testService。
var testservice = require('./TestService');
Template.allInventory.rendered = function() {
Template.allInventory.helpers({
productDetails: function() {
return testservice.getData();
}
})
}
channels.js我在哪裏設置從DB
var testservice = require('./TestService');
Template.channels.rendered = function(){
Meteor.call('getDetialsFromDB',function(err, res){
if(res){
console.log("res is...getAllProductDetail.."+res);
testservice.setData(res);
}
if(err){
console.log("Error while calling getAllProductDetail");
}
})
未來如果我叫上面的方法,而無需使用比其服務呈現模板,沒有任何數據,因爲數據從後端取來的數據有一段時間,如:
Template.allInventory.rendered = function() {
Template.allInventory.helpers({
productDetails: function() {
var data;
Meteor.call('getDetialsFromDB',function(err, res){
if(res){
console.log("res is...getAllProductDetail.."+res);
data = res;
}
if(err){
console.log("Error while calling getAllProductDetail");
}
})
return res;
}
})
,所以我只是想使我的數據從服務器端的流星。方法之一來從客戶端調用或請給任何例如
任何幫助將appriciated! 謝謝