【问题标题】:TypeError: p is undefined when using xtype: 'treepicker'. Extjs6TypeError: p 在使用 xtype: 'treepicker' 时未定义。 Extjs6
【发布时间】:2019-06-04 17:37:29
【问题描述】:

在记录编辑窗口中,我需要使用树状选择器,为此,文件Ext.ux.TreePicker包含在app.js文件中,该文件位于与@同级的app文件夹中987654325@文件。

Ext.Loader.setConfig({enabled:true});
Ext.Loader.setPath('Ext.ux', 'app');
Ext.application({
    extend: 'Ext.app.Application',
    name: 'App',    
    appFolder: 'app',
    requires: ['Ext.ux.TreePicker'], 
...

在记录编辑窗口中,设置xtype: 'treepicker'字段:

Ext.define('App.view.OperationEdit', {
    extend: 'Ext.window.Window',
    xtype: 'operation-edit',
    alias: 'widget.operationedit',    
    controller: 'operation_controller',  
    viewModel: {
        type: 'operation_model'
    },                  
    defaults: {
        xtype: 'textfield',
        margin: 10,
        labelAlign: 'top'
    },    
    closable: true,
    items: [{
        xtype: 'form',      
            items: [
{           
    xtype: 'treepicker',
    store: Ext.data.StoreManager.get('StorageStore'),
    fieldLabel: "Mesto_hraneniya",
    valueField: 'id',
    displayField: 'text',
    selectChildren: true,
    canSelectFolders: true,
    name: 'mesto_hraneniya'    
 },
......

当我打开编辑窗口时,我得到一个错误:

TypeError: p is undefined

示例链接Fiddle

为什么会出现错误?如何正确显示treepicker字段?

谢谢

【问题讨论】:

  • 为什么不在 fiddle.sencha.com 分享一个小提琴,这样更容易帮助?
  • @abeyaz 我在问题的示例中添加了一个链接,但由于某种原因 TreePicker.js 文件不想连接。在本地应用程序中,发生文件连接。
  • 您必须选中软件包列表底部的“ux”复选框才能使其正常工作。
  • @abeyaz 当我选中 Ux 框并打开记录进行编辑时,出现错误:TypeError: item is undefined 。 Treepicker 位于 app/view/TestEdit.js 编辑窗口中。添加或编辑记录时会打开此窗口
  • 检查我的答案,我成功了。

标签: javascript extjs


【解决方案1】:

您的代码中的问题,至少在您的小提琴中是您将“编辑表单”定义为完全 json,它将在加载时被解析和执行。由于在加载时没有 StorageStore,因此 treepicker 的 store 参数将为 null,这就是您收到错误的原因。正确的方法是在对象实例化上设置表单项,如下所示,工作小提琴是here

Ext.define('App.view.TestEdit', {
    extend: 'Ext.window.Window',
    xtype: 'test-edit',
    alias: 'widget.testedit',
    requires: ['App.store.StorageStore'],
    controller: 'app_view_testgrid',
    defaults: {
        xtype: 'textfield',
        margin: 10,
        labelAlign: 'top'
    },
    closable: true,
    items: [],

    initConfig: function(config){
        config = config || {};
        config.items = [
            {
            xtype: 'form',
            items: [{
                xtype: 'combobox',
                store: {
                    type: 'type-store'
                },
                fieldLabel: 'Type',
                displayField: 'name',
                valueField: 'id',
                name: 'id_type',
                reference: 'mycombo',

            }, {
                xtype: 'textfield',
                fieldLabel: 'My field',
                name: 'mytextfield'
            }, {
                xtype: 'treepicker',
                store: Ext.data.StoreManager.get("StorageStore"),
                fieldLabel: "Mesto_hraneniya",
                valueField: 'id',
                displayField: 'text',
                selectChildren: true,
                canSelectFolders: true,
                name: 'mesto_hraneniya'
            }, {
                xtype: 'button',
                minWidth: 70,
                text: 'Save',
                listeners: {
                    click: 'saveRecord'
                }
            }]
        }    
        ];
        this.callParent(arguments);
    }
});

【讨论】:

  • 是否可以在 ViewController 中,在打开窗口之前通过使用 'reference:' 建立连接来加载存储 StorageStore?为组合框制作
  • 非常感谢。只有一个澄清,为什么'mesto_hraneniya'字段的既定值没有以开放形式显示?
  • 因为你没有在记录中使用“id”。您可以使用valueField 设置组合或选择器字段的值,在本例中为id。检查你是如何处理类型字段的,你应该遵循相同的方法。
  • 谢谢。我在 json 数据中添加了 'name: 'mesto_hraneniya_id'' 并添加了值 'mesto_hraneniya_id'。它的工作
猜你喜欢
  • 2021-08-24
  • 1970-01-01
  • 2020-09-06
  • 2017-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多