[英]Extjs sencha compiled app throws Uncaught TypeError: Object prototype may only be an Object or null
[英]Uncaught TypeError: Object prototype may only be an Object or null with ExtJS in Symfony 2
我在Symfony 2中有一個與Sonata的Admin-Bundle一起顯示的實體列表。我已覆蓋該列表以添加一個按實體顯示地圖圖標的自定義列。 然后,當有人單擊該圖標時,它將顯示一個彈出窗口。 彈出窗口由ExJS 4構建。
當我的列表中只有一個實體時,彈出窗口將正確顯示。
Bu當我有多個實體(然后是x映射圖標)時,彈出窗口不再顯示,並且在控制台中出現此錯誤:
未捕獲到的TypeError:對象原型只能是Object或為null
如果我有7個實體,則錯誤顯示7次。
這是我的樹枝代碼:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field%}
{% javascripts '@AAAAdminBundle/Resources/public/js/ExtJS4.2/ext-all-debug.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-gray.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') }}"
style="cursor:pointer;"
id="popup-map">
</div>
{% endblock %}
這是我的JS代碼:
Ext.require([
'Ext.container.Viewport',
'Ext.window.MessageBox',
'Ext.layout.container.Fit',
]);
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: 0
},
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;
});
}
});
}
});
有人知道為什么嗎?
編輯:通過查看頁面的源代碼,似乎為列表的每一行加載了JS文件。 也許問題出在那兒,它可以解釋為什么只有一行時(以及JS的一個負載)它工作的原因。
在向前看之后,問題不是出自我的JS代碼,而是由於如果我在網格中顯示了多個實體,那么ext-all-debug.js的加載時間與實體相同。 然后似乎會產生錯誤。
我想我可以將庫移到Sonata的主要模板。 我試過了,有一些錯誤,但是工作效率更高。
但是,我想這不是正確的解決方案,因為我不想觸及奏鳴曲模板。
如果找到解決方案,我將對其進行更新。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.