[英]Issue calling javascript (ExtJS) in a twig extended a Sonata admin twig / Symfony 2
我是php技術的新手。 我面臨一些我無法解決的問題。
為了快速總結,我在Sonata Admin-Bundle生成的管理列表中添加了一個自定義列。
在此列中,我有一個地圖圖標。 目前,該圖標正在運行。
當我單擊該圖標時,我想要的是打開由ExtJS生成的彈出窗口。
我已經測試過將ExtJS集成到Symfony(不是Sonata)樹枝中,並且可以正常工作。
但是當我用自定義樹枝嘗試相同的東西時,
base_list_field.html.twig
我在調試工具中遇到錯誤,當然彈出窗口沒有顯示。 這是我的樹枝代碼:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field%}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
{% javascripts '@AAAAdminBundle/Resources/public/js/ExtJS4.2/ext-all.js' %}
<script src="{{ asset_url }}"></script>
<script>
Ext.Loader.setPath('Ext', '/bundles/aaaadmin/js/ExtJS4.2/src');
</script>
{% endjavascripts %}
{% stylesheets 'bundles/aaaadmin/js/ExtJS4.2/resources/css/ext-all-neptune.css' filter='cssrewrite' %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
{% javascripts '@AAAAdminBundle/Resources/public/js/popup.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
<div>
<img src="{{ asset('bundles/aaaadmin/images/map_magnify.png') }}" alt="exemple onclick" style="cursor:pointer;" id="popup-map" />
</div>
{% endblock %}
這是我的JS代碼:
Ext.require([
'Ext.container.Viewport',
'Ext.state.Manager',
'Ext.state.CookieProvider',
'Ext.window.MessageBox',
'Ext.chart.*',
'Ext.fx.target.Sprite',
'Ext.layout.container.Fit',
'Ext.window.MessageBox',
]);
Ext.application({
name: 'popup',
launch: function() {
var popup,
button = Ext.get('popup-map');
button.on('click', function(){
if (!popup) {
popup = Ext.create('widget.window', {
title: 'Pop-Up',
id: 'popup',
header: {
titlePosition: 2,
titleAlign: 'center'
},
border: false,
closable: true,
closeAction: 'hide',
width: 800,
minWidth: 400,
maxWidth: 1200,
height: 500,
minHeight: 550,
maxHeight: 800,
tools: [{type: 'help'}],
layout: {
type: 'border',
padding: 10
},
items: [
{
region: 'center',
xtype: 'tabpanel',
plain: true,
items: [
{
title: 'Carte',
html: 'On mettra la carte ici',
border: false,
},
{
title: 'Description',
html: 'Attributs de l\'objet sous forme de tableau',
border: false,
}
]
}
]
});
}
button.dom.disabled = true;
if (popup.isVisible()) {
popup.hide(this, function() {
button.dom.disabled = false;
});
} else {
popup.show(this, function() {
button.dom.disabled = false;
});
}
});
}
});
的
button = Ext.get('popup-map');
在我所做的測試中努力引用HTML對象。 但是然后我有很多錯誤,例如
Object prototype may only be an Object or null //5 times this error when loading the page
Object [object Object] has no method 'addCls'
Object [object Object] has no method 'hasCls' // when I click somewhere on the page
我有點迷失:(。任何提示將不勝感激。
在向前看之后,問題不是出自我的JS代碼,而是由於如果我在網格中顯示了多個實體,那么ext-all-debug.js的加載時間與實體相同。 然后似乎會產生錯誤。
我想我可以將庫移到Sonata的主要模板。 我試過了,有一些錯誤,但是工作效率更高。
但是,我想這不是正確的解決方案,因為我不想觸及奏鳴曲模板。
如果找到解決方案,我將對其進行更新。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.