我有一个关于ember-leaflet
库和正确使用弹出窗口的问题。
ember-leaflet
website中的以下示例使用库添加标记和链接弹出窗口。它还说明了如何通过内容绑定为弹出窗口添加内容。
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
属性使用视图或句柄栏模板。有人知道如何实现这一点吗?对于这种情况,有什么最佳实践吗?
我的第一个方法是:
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()
});
这会导致以下错误:
Uncaught TypeError: Cannot call method 'push' of undefined
希望有人能帮上忙。
发布于 2013-10-03 01:26:34
我是个小笨蛋,不能在文档中查找帮助函数。
我通过一个小技巧和Ember.View#createElement
的帮助解决了这个问题
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()
});
希望这能对其他人有所帮助。
https://stackoverflow.com/questions/19119021
复制相似问题