admin管理员组文章数量:1392002
I am trying to load data to store using a json file. But getCount is returning 0.Store and asset.json are in the same folder. What changes do I need to make?
Code for the Model:
Ext.define('Nm.model.analysis.Asset', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.Field'
],
fields: [
{
name: 'assetType',
type: 'string'
},
{
name: 'referenceNo',
type: 'string'
},
{
name: 'action',
type: 'int'
}
]
});
Store I am trying to create :
var store = Ext.create('Ext.data.Store', {
model: 'Nm.model.analysis.Asset',
proxy: {
type: 'rest',
url : 'asset.json',
reader: {
type: 'json',
rootProperty: 'assets'
}
},
listeners : {
load : function(store) {
alert('getcount from listener '+store.getCount());
}
}
});
store.load();
alert("getcount="+store.getCount());
Data in asset.json
{
"assets" : [
{
"assetType" : 'hello',
"referenceNo" : 'refNo.1',
"action" : 2
},
{
"assetType" : 'new',
"referenceNo" : 'refNo.2'
}
]
}
I am trying to load data to store using a json file. But getCount is returning 0.Store and asset.json are in the same folder. What changes do I need to make?
Code for the Model:
Ext.define('Nm.model.analysis.Asset', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.Field'
],
fields: [
{
name: 'assetType',
type: 'string'
},
{
name: 'referenceNo',
type: 'string'
},
{
name: 'action',
type: 'int'
}
]
});
Store I am trying to create :
var store = Ext.create('Ext.data.Store', {
model: 'Nm.model.analysis.Asset',
proxy: {
type: 'rest',
url : 'asset.json',
reader: {
type: 'json',
rootProperty: 'assets'
}
},
listeners : {
load : function(store) {
alert('getcount from listener '+store.getCount());
}
}
});
store.load();
alert("getcount="+store.getCount());
Data in asset.json
{
"assets" : [
{
"assetType" : 'hello',
"referenceNo" : 'refNo.1',
"action" : 2
},
{
"assetType" : 'new',
"referenceNo" : 'refNo.2'
}
]
}
Share
Improve this question
asked Nov 18, 2014 at 6:52
AnkitaAnkita
1891 gold badge3 silver badges19 bronze badges
3
-
Try:
getTotalCount()
. Check what is the result. – Sujata Chanda Commented Nov 18, 2014 at 6:54 - Can you try changing the url to '/asset.json' – Srinivas B Commented Nov 18, 2014 at 7:14
- Put a break point in the store load function and check whether your store has real data or not.If data is there then it should return the count. – Sreek521 Commented Nov 18, 2014 at 7:56
1 Answer
Reset to default 6This is valid code. Here is working fiddle. You need to make sure you are calling store.getCount()
after store has been loaded. store.load is async!! ... so doing store.load();
and then console.log(store.getCount());
is never going to print > 0. Use declarative or other kind of listener:
listeners: {
load: function(store, records, successful) {
Ext.Msg.alert('Store count A', 'count: ' + store.getCount());
}
}
or
store.on('load', function(store, records, successful){
Ext.Msg.alert('Store count A', 'count: ' + store.getCount());
});
store.load();
本文标签: javascriptExtjs storegetCount() returns 0Stack Overflow
版权声明:本文标题:javascript - Extjs store.getCount() returns 0 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744762451a2623832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论