使用Sencha Docs网站上的示例时找不到Plant.js文件

问题描述 投票:0回答:1

当我使用Sencha Docs网站上的示例时,我遇到了错误。这个例子是一个网格,你可以找到here

所以我试图复制所有代码,但由于某种原因它对我不起作用。

app.js

    const test = Ext.define('KitchenSink.view.grid.CellEditing', {
        extend: 'Ext.grid.Panel',

        requires: [
            'Ext.selection.CellModel',
            'Ext.grid.*',
            'Ext.data.*',
            'Ext.util.*',
            'Ext.form.*',
            'KitchenSink.model.grid.Plant'
        ],
        xtype: 'cell-editing',


        title: 'Edit Plants',
        frame: true,

        initComponent: function() {
            this.cellEditing = new Ext.grid.plugin.CellEditing({
                clicksToEdit: 1
            });

            Ext.apply(this, {
                width: 680,
                height: 350,
                plugins: [this.cellEditing],
                store: new Ext.data.Store({
                    // destroy the store if the grid is destroyed
                    autoDestroy: true,
                    model: KitchenSink.model.grid.Plant,
                    proxy: {
                        type: 'ajax',
                        // load remote data using HTTP
                        url: 'resources/data/grid/plants.xml',
                        // specify a XmlReader (coincides with the XML format of the returned data)
                        reader: {
                            type: 'xml',
                            // records will have a 'plant' tag
                            record: 'plant'
                        }
                    },
                    sorters: [{
                        property: 'common',
                        direction:'ASC'
                    }]
                }),
                columns: [{
                    header: 'Common Name',
                    dataIndex: 'common',
                    flex: 1,
                    editor: {
                        allowBlank: false
                    }
                }, {
                    header: 'Light',
                    dataIndex: 'light',
                    width: 130,
                    editor: new Ext.form.field.ComboBox({
                        typeAhead: true,
                        triggerAction: 'all',
                        store: [
                            ['Shade','Shade'],
                            ['Mostly Shady','Mostly Shady'],
                            ['Sun or Shade','Sun or Shade'],
                            ['Mostly Sunny','Mostly Sunny'],
                            ['Sunny','Sunny']
                        ]
                    })
                }, {
                    header: 'Price',
                    dataIndex: 'price',
                    width: 70,
                    align: 'right',
                    renderer: 'usMoney',
                    editor: {
                        xtype: 'numberfield',
                        allowBlank: false,
                        minValue: 0,
                        maxValue: 100000
                    }
                }, {
                    header: 'Available',
                    dataIndex: 'availDate',
                    width: 95,
                    renderer: Ext.util.Format.dateRenderer('M d, Y'),
                    editor: {
                        xtype: 'datefield',
                        format: 'm/d/y',
                        minValue: '01/01/06',
                        disabledDays: [0, 6],
                        disabledDaysText: 'Plants are not available on the weekends'
                    }
                }, {
                    xtype: 'checkcolumn',
                    header: 'Indoor?',
                    dataIndex: 'indoor',
                    width: 90,
                    stopSelection: false
                }, {
                    xtype: 'actioncolumn',
                    width: 30,
                    sortable: false,
                    menuDisabled: true,
                    items: [{
                        icon: 'resources/images/icons/fam/delete.gif',
                        tooltip: 'Delete Plant',
                        scope: this,
                        handler: this.onRemoveClick
                    }]
                }],
                selModel: {
                    selType: 'cellmodel'
                },
                tbar: [{
                    text: 'Add Plant',
                    scope: this,
                    handler: this.onAddClick
                }]
            });

            this.callParent();

            this.on('afterlayout', this.loadStore, this, {
                delay: 1,
                single: true
            })
        },

        loadStore: function() {
            this.getStore().load({
                // store loading is asynchronous, use a load listener or callback to handle results
                callback: this.onStoreLoad
            });
        },

        onStoreLoad: function(){
            Ext.Msg.show({
                title: 'Store Load Callback',
                msg: 'store was loaded, data available for processing',
                icon: Ext.Msg.INFO,
                buttons: Ext.Msg.OK
            });
        },

        onAddClick: function(){
            // Create a model instance
            var rec = new KitchenSink.model.grid.Plant({
                common: 'New Plant 1',
                light: 'Mostly Shady',
                price: 0,
                availDate: Ext.Date.clearTime(new Date()),
                indoor: false
            });

            this.getStore().insert(0, rec);
            this.cellEditing.startEditByPosition({
                row: 0, 
                column: 0
            });
        },

        onRemoveClick: function(grid, rowIndex){
            this.getStore().removeAt(rowIndex);
        }
    })
    Ext.application({
        name: 'MyApp',
        launch: function() {
            Ext.create('Ext.container.Viewport', {
                items: [{
                    items: test
                }]
            })
        }
    })

index.html

<html> 
  <head>
        <!-- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> -->
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <!-- <link rel='shortcut icon' href='./imatges/icones/petits/login.png' type='image/png'> -->

        <title>Sencha</title>

        <!-- CDN 4.2.1- NEPTUNE -->
        <link href="http://cdn.sencha.io/ext/gpl/4.2.1/resources/css/ext-all-neptune.css" rel="stylesheet" />
        <script src="http://cdn.sencha.com/ext/gpl/4.2.1/ext-all.js"></script>
        <link href="http://cdn.sencha.io/ext/gpl/4.2.1/resources/css/ext-all-neptune.css" rel="stylesheet" />

        <!-- JScript -->
        <script type="text/javascript" src="app.js"></script>
    </head>

    <body>
    </body>

</html>

当我在浏览器上打开它时,我不断收到此错误:

为什么它不起作用以及如何解决这个问题?

谢谢

extjs extjs4.2
1个回答
2
投票

您正在使用应用名称CellEditing定义model.grid.PlantKitchenSink

const test = Ext.define('KitchenSink.view.grid.CellEditing',{
 //rest of your code

requires: [
            //other requires
            'KitchenSink.model.grid.Plant'
        ]
store: new Ext.data.Store({
                    // destroy the store if the grid is destroyed
                    autoDestroy: true,
                    model: KitchenSink.model.grid.Plant,
                    //rest of store

onAddClick: function(){
            // Create a model instance
            var rec = new KitchenSink.model.grid.Plant({
                //rest of model configs

但是在Ext.application中,您将应用程序的名称定义为“MyApp”:

Ext.application({
    name: 'MyApp',
    //other configs

将应用程序的名称更改为KitchenSink或定义CellEditing,需求和模型,如:

const test = Ext.define('MyApp.view.grid.CellEditing',{
     //rest of your code

看看它是否有效。

© www.soinside.com 2019 - 2024. All rights reserved.