首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在传单弹出窗口中呈现视图或把手模板

在传单弹出窗口中呈现视图或把手模板
EN

Stack Overflow用户
提问于 2013-10-01 22:35:46
回答 1查看 1.4K关注 0票数 3

我有一个关于ember-leaflet库和正确使用弹出窗口的问题。

ember-leaflet website中的以下示例使用库添加标记和链接弹出窗口。它还说明了如何通过内容绑定为弹出窗口添加内容。

代码语言:javascript
复制
RadMarkersApp = Ember.Application.create();
RadMarkersApp.MarkerLayer =
  EmberLeaflet.MarkerLayer.extend(
    EmberLeaflet.DraggableMixin,
    EmberLeaflet.PopupMixin, {
  popupContentBinding: 'content.title'
});

RadMarkersApp.MarkerCollectionLayer =
  EmberLeaflet.MarkerCollectionLayer.extend({
    content: [{
      location: L.latLng(40.7127, -74.0060),
      title: 'City Hall'}],
    itemLayerClass: RadMarkersApp.MarkerLayer
  });

RadMarkersApp.IndexView =
  EmberLeaflet.MapView.extend({
    childLayers: [
      EmberLeaflet.DefaultTileLayer,
      RadMarkersApp.MarkerCollectionLayer]});

现在,我希望能够在这里为popupContent属性使用视图或句柄栏模板。有人知道如何实现这一点吗?对于这种情况,有什么最佳实践吗?

我的第一个方法是:

代码语言:javascript
复制
App.MarkerLayer =
  EmberLeaflet.MarkerLayer.extend(
    EmberLeaflet.PopupMixin, {

    popupContent: function() {
      // Render view (how to get?) or handlebars template
      return Ember.TEMPLATES['popup-content'](this.get('content'))
    }.property()
  });

这会导致以下错误:

代码语言:javascript
复制
Uncaught TypeError: Cannot call method 'push' of undefined 

希望有人能帮上忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-03 01:26:34

我是个小笨蛋,不能在文档中查找帮助函数。

我通过一个小技巧和Ember.View#createElement的帮助解决了这个问题

代码语言:javascript
复制
App.MarkerLayer = EmberLeaflet.MarkerLayer.extend(EmberLeaflet.PopupMixin, {
  popupContent: function() {
    view = this.view = this._parentLayer.createChildView('map-popup');
    view.set('context', this.get('content'));
    Ember.View.states.inDOM.enter(view)
    view.createElement();

    return view.get('element');
  }.property()
});

希望这能对其他人有所帮助。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19119021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档