PDA

View Full Version : Extending Ext.Util.Observable



ajay.kumar2
12 Nov 2010, 10:44 AM
I have created a custom object which extends from
Ext.Util.Observable,
I want to make server request ,get the json response and store it in
Ext.Util.MixedCollection and expose a
getDisplayFieldValue in it to fetch the value of the json respone property.

The json response which comes from the server is:-


{"Property1":"true","Property2":"false","Property3":"true"}


Inside Ext.onReady i want to use this custom object and fetch the property value
i.e
customObject.getDisplayFieldValue('Property1') this should give me true.

I am not able to achieve this. Please guide me. thanks in advance

Custom Object Code:-



com.test.ScreenDefinition=Ext.extend(Ext.util.Observable,{
screenDefRecords:new Ext.util.MixedCollection(false),
screenDefRequestId:'',
screenDefResponse:'',
initComponent:function(){

var config = {url:this.url};

Ext.apply(this, Ext.apply(this.initialConfig, config));

com.test.ScreenDefinition.superclass.initComponent.apply(this, arguments);

this.loadScreenDefinitions();

},
loadScreenDefinitions:function(){

screenDefRequestId = Ext.Ajax.request({
url: ContextPath+'/GetScreenDefinitions',
method:'GET',
params:{jsonRequest:'true'},
success: function(response,request){
alert('success');
screenDefResponse=response.responseText();
var jsonResponse = Ext.util.JSON.decode(response.responseText);

this.screenDefRecords.addAll(jsonResponse);
},
failure:function(response, request){
Ext.msg.alert('Ajax request failure');
}

});

},
getDisplayFieldValue: function(fieldName){

return this.screenDefResponse;
},
isLoading:function(){
return Ext.Ajax.isLoading(this.screenDefRequestId);
}



});

Animal
12 Nov 2010, 12:08 PM
It is not a Component. The constructor does not call initComponent.

So, you must have just copied that whole concept.

ajay.kumar2
12 Nov 2010, 2:10 PM
It is not a Component. The constructor does not call initComponent.

So, you must have just copied that whole concept.

I tried changing initComponent to


constructor:function(config){
}


but now i get error com.test.ScreenDefinition is not a constructor

when i am doing new com.test.ScreenDefinition()

Please provide some guidance, i am new to extjs.

Animal
13 Nov 2010, 1:03 AM
You still have to assign com.test.ScreenDefinition to the result of the Ext.extend call!

plalx
13 Nov 2010, 7:39 AM
Also, remember that objects and arrays are passed by reference in JavaScript, meaning that if you have an object or array that is part of a class prototype, it will be shared between all instances.

E.g.


screenDefRecords:new Ext.util.MixedCollection(false) //This will be shared between all instances