我在名爲「map」的模板中的每個頁面上都有一個傳單地圖的應用程序。 在該圖中,我在「Template.map.rendered」函數中添加了一個contextmenu。Meteor.js - 如何在登錄時重新渲染模板
凡變得棘手,是我想要添加在文本菜單斷開鏈接和一個配置文件鏈接,當用戶登錄,但不是當用戶不在。 即使沒有連接,地圖也在那裏。
我的問題,現在的問題是,當我登錄或應用程序的註銷我的地圖是不是重新呈現。 我嘗試了幾個我在谷歌上找到的解決方案,但似乎沒有任何工作,我在這裏有點失落。
這是我的第一個流星應用。
代碼:
Template.map.rendered = function(){
L.Icon.Default.imagePath = 'packages/leaflet/images';
var map = L.map('map', {
doubleClickZoom: false,
contextmenu: true,
contextmenuWidth: 160,
contextmenuItems: [{
text: 'Show coordinates',
callback: function(event){
console.log(event);
},
icon: 'images/icons/mini-map-pin.png'
}]
}).setView([Session.get('mapLatitude'), Session.get('mapLongitude')], Session.get('mapZoom'));
map.on('dragend zoomend', function(event){
//map position and zoom are saved in session on every action so they
//stay the same when the template is rerendered
Session.set("mapLatitude", map.getCenter().lat);
Session.set("mapLongitude", map.getCenter().lng);
Session.set("mapZoom", map.getZoom());
});
if(Meteor.loggingIn()){
map.contextmenu.addItem('-');
map.contextmenu.addItem({
text: 'My profile',
callback: function(event){
console.log(event);
},
icon: 'images/icons/profile.png'
});
map.contextmenu.addItem({
text: 'Disconnect',
callback: function(event){
console.log(event);
},
icon: 'images/icons/logout.png'
});
}
L.tileLayer.provider('OpenStreetMap.BlackAndWhite').addTo(map);
}
地圖模板只是這個
template(name="map")
div#map
以及登錄是標準的 「帳戶基」 與 「帳戶的用戶界面的自舉-3」
編輯:啊,我用玉來代替火焰如果改變的東西
對於這個問題的答案以及感謝,如果不是溶液,然後在它至少回答很多問題,我有,像在哪裏使用自動運行。 Leaflet contextmenu插件沒有添加和刪除項目功能,所以我會這樣做。我一開始想這樣做,但不知道如何在流星中做到這一點。 – jfmmm
完美無瑕,再次感謝! – jfmmm