How to specify model name in store of an extjs 4?

我是研究僧i 提交于 2020-01-05 02:44:47

问题


I am getting frustrated while working with store and model of extjs 4. I am getting Store defined with no model. You may have mistyped the model name. error even though I have specified model name inside store.

Here is my code :

Ext.define('iWork.store.CandidateDistribution', {
    extend: 'Ext.data.TreeStore',
    autoLoad: true,
    requires: 'iWork.model.Location',
    model: 'iWork.model.Location',

    proxy: {
        type: 'ajax',
        url: 'data/CandidateDistribution/CandidateCount.json',
        reader: {
            type: 'pentahoReader',
            root: 'resultset'
        }
    },
    listeners: {
        load: function(treeStore, currentNode, records, success, options) {
            console.log('in load listener');
            console.log(records);
        },
        beforeappend: function(currentNode, newNode, options) {
            console.log('in beforeAppend listener');

        },
        add: function(store, records, options) {
            console.log('in add listener');
        },
        beforeinsert: function(currentNode, newNode, option) {
            console.log('in beforeInsert listener');
        }
    }
});

I tried changing model: 'iWork.model.Location', to model: 'Location', model: "Location", and to model: "iWork.model.Location" but still its not working.

Code in model file is as follows:

Ext.define('iWork.model.Location', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name', type: 'string'},
        {name: 'candidateCount', type: 'string'}
    ]
});

and treepanel code which references this store is as follows :

Ext.define('iWork.view.CandidateDistribution', {
    extend: 'Ext.window.Window',
    alias: 'widget.candidateDistribution',
    require: ['iWork.store.CandidateDistribution'],
    layout: {
        type: 'hbox',
        align: 'stretch'
    },
    autoShow: true,

    initComponent: function() {
        this.items = [
            {
                xtype: 'treepanel',
                title: 'Location wise customer Distribution',
                store: 'iWork.store.CandidateDistribution',
                width: '25%',
                height: '100%',
                rootVisible: false
            }
        ];
        this.callParent(arguments);
    }
});

I have tried to change store: 'iWork.store.CandidateDistribution' to store: 'CandidateDistribution' but then also its not working.

If I change store: 'iWork.store.CandidateDistribution' to store: CandidateDistribution, I get following error in ext-debug.js (line 8002)

me.store is undefined
[Break On This Error] }, 

I am not able to find where have I made mistake. Please let me know if I have missed any other configuration or what I have done wrong.

Thanks !!


EDIT 1 : index.html file of my app looks as follows :

<html>
    <head>
        <title>iWork Dashboards</title>
        <link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css" />
        <script type="text/javascript" src="../extjs/ext-debug.js"></script>
    <script type="text/javascript" src="app/app.js"></script>
    <script type="text/javascript" src="app/PentahoReader.js"></script>
    </head>
    <body>
    </body>
</html>


回答1:


This is a bug in NodeStore, which is used by Ext.tree.View. You will always see this when you use a Tree Panel.

If you break on the line that generates the warning, and look at the stack, you'll see that it's in the AbstractStore's constructor which has been called by the NodeStore's constructor, which in turn is called by Tree View's initComponent.



来源:https://stackoverflow.com/questions/9293511/how-to-specify-model-name-in-store-of-an-extjs-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!