node.updateInfo is not a function while appending node in extjs - extjs4

I am trying to load data into an extjs 4 TreeStore but while appending node, I am getting node.updateInfo is not a function error.
My model classes are as follows :
Dimension.js
Ext.define('ilp.model.Dimension', {
extend : 'Ext.data.Model',
require : [
'ilp.model.DimensionLevel'
],
fields : [
'actualName',
'displayName'
],
hasMany : {model : 'ilp.model.DimensionLevel', name : 'dimensionLevels'}
});
DimensionLevel.js
Ext.define('ilp.model.DimensionLevel', {
extend : 'Ext.data.Model',
fields : [
{name : 'name', type : 'string'},
{name : 'totalTrainees', type : 'int'}
]
});
and tree store code is as follows :
Ext.define('ilp.store.DimensionTree', {
extend : 'Ext.data.TreeStore',
requires : [
'ilp.model.Dimension',
'ilp.model.DimensionLevel'
],
model : 'ilp.model.Dimension',
root: {
name: 'Dimensions'
},
proxy: {
type: 'ajax',
url: 'http://localhost:8080/pentaho/content/cda/doQuery',
reader: {
type: 'pentahoReader',
root: 'resultset'
},
extraParams: {
path: 'RINXDashboards%2FCDAs%2FILP_Employee_Qeries.cda',
dataAccessId:'Get_All_Levels_From_All_Dimensions',
userid : 'joe',
password : 'password'
}
},
listeners: {
append : function(parentNode, newNode, index, options) {
if(newNode.get('text') != 'Root') {
console.log('newNode text value = ' + newNode.get('text'));
newNode.set('checked', null);
newNode.set('expandable', true);
if(Ext.ClassManager.getName(newNode) == "ilp.model.Dimension") {
newNode.set('expanded', true);
newNode.set('text', newNode.get('displayName'));
if(newNode.dimensionLevels().getCount() > 0) {
newNode.dimensionLevels().each(function(level) {
newNode.appendChild(level);
});
} else {
newNode.set('leaf', true);
}
}else if(Ext.ClassManager.getName(newNode) == "ilp.model.DimensionLevel") {
newNode.set('leaf', true);
newNode.set('text', newNode.get('name'));
}
}
}
}
});
I am getting above error on following line :
newNode.dimensionLevels().each(function(level) {
while debugging I have found that updateInfo() method of newNode is undefined.
Can anyone please tell me why this error is coming? I am totally clueless now !!!

May this is caused by the bug EXTJSIV-6051
see Sencha Forum for further infos

I think your problem comes from :
root: {
name: 'Dimensions'
},
root attribute must be of type: Ext.data.Model/Ext.data.NodeInterface/Object. So try to replace 'root' attribute by this:
root: {
text: "Dimensions",
leaf: false
}
Check Sencha doc for more information: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.tree.Panel-cfg-root

Related

How to query for all Artifacts of a Milestone

I am attempting to create reports on Milestones using App SDK 2.0 and would like to find all User Stories that have been assigned to the Milestone.
I tried pulling out the Artifacts from a Milestone using getCollection.
Ext.create('Rally.data.wsapi.Store', {
model : 'Milestone',
filters : [ {
property : 'ObjectID',
operator : '=',
value : milestone.get("ObjectID")
} ],
fetch : [ 'Artifacts' ],
limit : Infinity,
autoLoad : true,
listeners : {
load : function(store, records) {
var record = records[0];
var info = record.get('Artifacts');
var count = info.Count;
record.getCollection('Artifacts').load({
fetch : [ 'ObjectID' ],
callback : function(records, operation, success) {
Ext.Array.each(records, function(artifact) {
console.log(artifact.get('ObjectID'));
});
}
});
}
}
});
I get the following error:
Uncaught Rally.data.ModelFactory.getModel(): Could not find registered
factory for type: Artifact sdk-debug.js:7078
From https://rally1.rallydev.com/slm/doc/webservice/, it doesn't seem that Milestones is query able on the User Story or PortfolioItem. I tried it anyway using Tasks syntax and it nothing was returned.
Ext.create('Rally.data.wsapi.Store', {
model : 'UserStory',
filters : [ {
property : 'Milestones',
operator : 'contains',
value : milestone.get("_ref")
} ],
fetch : [ 'ObjectID' ],
limit : Infinity,
autoLoad : true,
listeners : {
load : function(store, records) {
console.log(records);
}
}
});
There is a defect in AppSDK2 that it does not work with abstract types, e.g. Artifact, UserPermissions.
Your first code example ran into that defect.
But your second code example must work. I suspect if it does not work for you it is a matter of scoping. Perhaps the milestone you filter by is not in the project you are scoped to. You may hard code a project ref in the context of the store to make sure it is looking in the right project. I initially tested your code in my default project and it worked as is, and then I modified it as follows to make sure it finds a milestone in a non-default project:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
Ext.create('Rally.data.wsapi.Store', {
model : 'UserStory',
context:{
project: '/project/16662089077'
},
filters : [
{
property : 'Milestones',
operator : 'contains',
value : "/milestone/33215216897"
}
],
fetch : [ 'ObjectID' ],
limit : Infinity,
autoLoad : true,
listeners : {
load : function(store, records) {
console.log(records);
}
}
});
}
});

Sencha List shows no data

I have a ProfileView which should show some user data. This is the first time I am trying to get data from MySql and showing it on a Sencha view.
The view
Ext.define('MyApp.view.Profile', {
extend : 'Ext.Panel',
xtype : 'profileview',
requires : ['Ext.List', 'Ext.data.Store'],
config : {
layout: 'fit',
title : 'Profiel',
iconCls : 'user3',
cls : 'home',
scrollable : true,
styleHtmlContent : true,
html : ['<h1>Mijn Profiel</h1>'].join(""),
items : [Ext.create('Ext.List', {
title : 'Profile',
docked : 'top',
store : myStore,
show : function(list, opts) {
alert('list === ' + list);
console.log('List Shown: ' + list);
}
})]
}
});
var myStore = Ext.create("Ext.data.Store", {
model : "MyApp.model.User",
proxy : {
type : "ajax",
url : "php/get_user.php",
reader : {
type : "json"
// rootProperty : "users"
}
},
autoLoad : true
});
The data is returned correctly but nothing is shown, and this I am trying to figure out.
The Response
[{"ID":"19","USERNAME":"Annet","EMAIL":"annet#annet.nl"}]
I skipped the rootProperty because it is a single user.
The Model
Ext.define('MyApp.model.User', {
extend : 'Ext.data.Model',
config : {
fields : [{
name : 'ID',
type : 'int'
}, {
name : 'USERNAME',
type : 'string'
}, {
name : 'EMAIL',
type : 'string'
}]
}
});
So, why does the list not show anything ?
Update
I check to see it the store contains data and it does
map: Object
ext-record-1: Class
_data: Object
EMAIL: "annet#annet.nl"
ID: 19
USERNAME: "Annet"
id: "ext-record-1"
__proto__: Object
Why is it not picked up by the list? I tried DataView as well.
You need to use itemTpl, i changed code for you.
Ext.define('MyApp.view.Profile', {
extend : 'Ext.Panel',
xtype : 'profileview',
requires : ['Ext.List', 'Ext.data.Store'],
config : {
layout: 'fit',
title : 'Profiel',
iconCls : 'user3',
cls : 'home',
scrollable : true,
styleHtmlContent : true,
html : ['<h1>Mijn Profiel</h1>'].join(""),
items : [Ext.create('Ext.List', {
title : 'Profile',
docked : 'top',
itemTpl : '<div>{ID} <span> {USERNAME} </span> <span> {EMAIL} </span> </div>',
store : myStore,
show : function(list, opts) {
alert('list === ' + list);
console.log('List Shown: ' + list);
}
})]
}
});

Adding a AJAX response data to a store

How to add a data to a json store if my data is coming from a back end AJAX call.
my store is as follows .
Ext.define('MyApp.store.GeographyMasterStore', { extend: 'Ext.data.Store',
requires: [
'MyApp.model.GeographyMasterModel'
],
config: {
model: 'MyApp.model.GeographyMasterModel',
storeId: 'geographyMasterStore',
proxy: {
type: 'ajax',
reader: {
type: 'json'
}
}
}
});
And my model is as follows:
Ext.define('MyApp.model.GeographyMasterModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'Code'
},
{
name: 'Description'
},
{
name: 'Level_Code',
mapping: 'Level Code'
},
{
name: 'Name'
}
]
}
});
If I add the data like this
var geographyMasterStore = Ext.getStore('geographyMasterStore');
geographyMasterStore.add(<data from backend AJAX call>);
it does not show me the mapped field i.e. Level_Code
Usually I when add a record to the store like this :
Ext.create('App.model.MyModel', JSON.parse(response.responseText);
Where response is the response from an Ext.Ajax.request
Hope this helps
You need create a model:
var record = Ext.create('model.GeographyMasterModel', Ext.JSON.decode(response.responseText));
save the model:
record.save()
reload the store:
geographyMasterStore.load()

Unable to load data from a json file in sencha touch 2

I've trying to get the sencha touch 2 data management examples to work but with no use. Here is the code of a simple model and store that are not working (getCount returns 0).
Ext.define('MyClient.model.Product', {
extend:'Ext.data.Model',
config:{
fields:['name', 'image'],
proxy:{
type:'ajax',
url:'http://localhost/st2/Projets/my-client-sencha/data/products.json',
reader:{
type:'json',
rootProperty:'products',
successProperty:'success'
}
}
}
});
Ext.define('MyClient.store.ProductsStore', {
extend:'Ext.data.Store',
config:{
model:'MyClient.model.Product',
autoLoad:true,
autoSync:true
}
});
In the launch function I have these lines:
var prod = Ext.create('MyClient.store.ProductsStore');
prod.load();
alert(prod.getCount());
And finally here's my products.json:
[
{
"name":"test"
}
]
I'm not getting any errors in the console but still the getCount always returns 0. Can use some help here please.
EDIT: wrong JSON, not working with this neither:
{
"success":true,
"products": [
{
"name":"test"
}
]
}
Because of your setting rootProperty:'products', your json has to be like
{
products: [
{
"name":"test"
}
]
}
if you do not want to change server response remover rootProperty from config.
have a look at Json Reader doc
Ahh... you forgot about asyn nature of the load()....
var prod = Ext.create('MyClient.store.ProductsStore');
prod.load(function ( ){
alert(prod.getCount());
});
Notice that it prod.load() is using only for testing purposes, as far you have set property autoLoad: true.
In your snippet the loader would make 2 similar calls.
Cheers, Oleg
Ext.define('MyBizilinkms.model.Customer', {
extend: 'Ext.data.Model',
config: {
identifier:'uuid',
fields: [
'CustId',
'EMail',
'Title',
'FName',
'MdInitial',
'LName',
'PhnNum',
'SecondPhnNo',
'DOB',
'Address',
'SecondAddress',
'City',
'State',
'Zip',
'Country',
'RecieveEmail',
'IsSaveonServer',
{
name: 'Full_Name',
type:'string',
convert:function(v, rec) {
return rec.data.FName + " " + rec.data.LName;
}
}],
validations: [
{
type: 'format',
name: 'EMail',
matcher: /^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/,
message:"Valid Email Required"
},
{
name: 'PhnNum',
type : 'custom',
message : "Valid Phone required",
validator : function(config, value, model) {
var reg = /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/;
return reg.test(value);
}
},
{
name: 'SecondPhnNum',
type : 'custom',
message : "Valid 2nd Phone required",
validator : function(config, value, model) {
if (!Ext.isEmpty(value)) {
var reg = /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/;
return reg.test(value)
}
return true;
}
},
{
type: 'presence',
name: 'FName',
message : "First Name is required"
},
{
type: 'presence',
name: 'LName',
message : "Last Name is required"
},
{
type: 'presence',
name: 'Address',
message : "Address is required"
},
{
type: 'presence',
name: 'City',
message : "City is required"
},
{
name: 'State',
type : 'custom',
message : "Valid State required",
validator : function(config, value, model) {
var reg = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i;
if(Ext.isEmpty(value))
value = '00'
var state = value.replace(/^\s+|\s+$/g, "");
return reg.test(state)
}
},
{
name: 'Zip',
type : 'custom',
message : "Valid Zip required",
validator : function(config, value, model) {
var reg = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
return reg.test(value)
}
},
{
type: 'presence',
name: 'Country',
message : "Country is required"
}
]
},
getFullName: function() {
return this.get('FName') + '' + this.get( 'LName');
}
});

Store multi-level

I have the following json :
{"service":
{"description":"Export a list of amendments.","id":"504e1bf57e8d2fdd92b6c316cd000b25","name":"AT4AM_AmendmentsList","notes":"Export a list of amendments in a defined format, Word or XML.\r\n\r\n\"keywords\" : [ \"AT4AM\", \"DST\", \"Amendment\", \"Export\", \"Word\", \"XML\" ]","revision":"2-cd375cfd296ba97e934f12794d4930e9","status":"study","type":"entity",
"versions":[{"description":"v1.0 description...","id":"504e1bf57e8d2fdd92b6c316cd0017c0","version":1}]}}
I would like to display the list of versions into a grid.
here is my model :
Ext.define('XXXX.model.Version', {
extend: 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'string'
}, {
name : 'description',
type : 'string'
}, {
name : 'version',
type : 'string'
}],
belongsTo: 'XXXX.model.Service',
proxy: {
type: 'rest',
id: 'id',
url : 'http://localhost:8080/xxxxx/services/service',
reader: {
type: 'json',
root: 'versions'
}
}
});
Thanks for help
Medley
use root: 'service.versions' in your reader's config.
Here is the solution I found :
1 - I added this to the model 'Service'
{type: 'hasMany', model: 'XXXX.model.Version', name: 'versions'}
2 - I used the configured RestProxy to make a GET request
Ext.ModelManager.getModel('XXXX.model.Service').load(serviceId, {
success: function(service) {
// Now, it is possible to access to all the versions of a service
service.versions().each(function(version) {
listOfVersions.push(version.data);
});
}
});
Regards
Medley