【问题标题】:Uncaught TypeError: Object prototype may only be an Object or null with ExtJS in Symfony 2Uncaught TypeError: Object prototype may only be an Object or null with ExtJS in Symfony 2
【发布时间】:2013-12-19 14:55:07
【问题描述】:

我有一个在 Symfony 2 中与 Sonata 的 Admin-Bundle 一起显示的实体列表。 我已经覆盖了列表以添加一个按实体显示地图图标的自定义列。 然后,当有人单击该图标时,它会显示一个弹出窗口。 弹出窗口由 ExJS 4 构建。

当我的列表只有一个实体时,弹出窗口显示正确。

当我有多个实体(然后是 x 地图图标)时,弹出窗口不再显示,并且我在控制台中出现此错误:

未捕获的类型错误:对象原型可能只是一个对象或空

如果我有 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;
            });
        }
});
}
});

有人知道为什么吗?

edit : 通过查看页面的源代码,看起来像是为列表的每一行加载了 JS 文件。也许问题出在那儿,它可以解释为什么它在只有一行的情况下有效(因此只有一个 JS 负载)。

【问题讨论】:

    标签: javascript symfony extjs extjs4


    【解决方案1】:

    在期待之后,问题不是来自我的 JS 代码,而是因为如果我在网格中显示了多个实体,则加载 ext-all-debug.js 的时间与存在实体的时间相同. 然后它似乎会产生错误。

    我想我可以将库移至 Sonata 的主模板。我试过了,有一些错误,但它的工作效率更高。

    但是,我想这不是正确的解决方案,因为我不想接触奏鸣曲模板。

    如果我找到解决方案,我会及时更新。

    【讨论】:

      猜你喜欢
      • 2018-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多