【问题标题】:Calling collection data on helper在助手上调用收集数据
【发布时间】:2015-08-26 18:11:00
【问题描述】:

我正在尝试建立一个房屋租赁网站并为每个列表实施谷歌地图标记。我已经存储了集合中每所房子的纬度、经度及其标题。

但我无法在助手端调用 {{olat}},因为我可以在视图模板上充当每个占位符。如何在下面给出的助手中调用集合数据。

Template.listing.rendered = function() {
    var tmpl = this;

    VazcoMaps.init({}, function() {

        tmpl.mapEngine = VazcoMaps.gMaps();

        tmpl.newMap2.addMarker({
            lat: 28.6508, //replace this with lat,long variable stored in collection
            lng: 77.3152, //for each listing
            zoom: 11
            icon: '/images/mark.png',
            draggable: false
        });

    });

};

【问题讨论】:

    标签: javascript meteor meteor-helper


    【解决方案1】:

    因此,您的 olat 值在模板的 data context 上可用,并且您希望在 onRendered 挂钩中检索它。似乎是个打电话给Template.currentData()的好地方:

    Template.listing.onRendered(function () {
      var tmpl = this;
      var context = Template.currentData();
    
      VazcoMaps.init({}, function() {
        tmpl.mapEngine = VazcoMaps.gMaps();
    
        tmpl.newMap2.addMarker({
          lat: context.olat,
          lng: context.olong,
          zoom: 11,
          icon: '/images/mark.png',
          draggable: false
        });
      });
    });
    

    【讨论】:

    • 哇,伙计,真快。试一试。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 2020-09-30
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    相关资源
    最近更新 更多