using getStore on view reference does not work - extjs

I have defined a controller, and assigned refs in it like this:
refs:
[
{
ref: 'refugeDetails',
selector: 'refugedetails'
}
]
I have created a view with xtype = 'refugedetails', and in a function deleteAdmin in my controller I try to remove a record from the store of this view, like this
deleteAdmin: function(index) {
this.getRefugeDetails().getStore().removeAt(index);
}
But it doesn't work, so I tried to see in the same function if getStore returns something like
var st = this.getRefugeDetails().getStore();
if(st) Ext.Msg.alert('st', 'exists');
else Ext.Msg.alert('st', 'does not');
But I do not get an alert, and in the console I get "TypeError: Object [object global] has no method 'getStore'". Am I doing something wrong here?

You cant get store's object form panel.
you can use below code
var st = Ext.getStore('yourStoreId');
it will return object of store.

you can try this:
var store = Ext.data.StoreManager.lookup("RoleStore");
and the 'RoleStore' is you defined
Ext.define("PRO.store.role.RoleStore", {});

Related

Value from $rootScope is not loaded properly

So I'm basically trying to get a property from my $rootScope when the page loads. I need this property so I can display the value in my form.
After testing this:
console.log("DEBUG $rootScope", $rootScope);
console.log("DEBUG $rootScope.localClient", $rootScope.localClient);
I've noticed that $rootScope contains a localClient property, but $rootScope.localClient is undefined. Why is this?
See console screen below.
Here is where I fill the localClient object
function setClient(client, tvaNumber) {
if (tvaNumber) {
if (angular.isUndefined($rootScope.localClient))
$rootScope.localClient = {};
$rootScope.localClient[tvaNumber] = client;
}
}
Try accessing it like this,
console.log("DEBUG $rootScope.localClient", $rootScope['localClient']);
You must make sure the attribute loaded before use it, because JavaScripte always pass a reference to an object. Or you can try console.log(JSON.parse(JSON.stringify($rootScope)) get the real value.
One example:
var a = {}; console.log(a);a.test = '1';

Passing JSON object as parameter from View to Controller function?

Basically I've a panel called DummyPanel, Now on dummypanel initialize event I've called a controller function like as follows:
var me = component;
var fieldCollection =
{
"Order" : 'ordNumber',
"Ref": 'refNumber'
};
me.fireEvent('myControllerFunction','Param1', fieldCollection, 'Param3');
Now I want to get fieldCollection JSON object value within function myControllerFunction, to get value from fieldCollection I'm using following code:
myControllerFunction(param1, collection, param3)
{
Ext.Msg.alert(collection.Order);
}
But it does not return anything. So please let me know how to resolve this problem!!
Any comment will appreciated!!
I'm not quite sure what it means "But it does not return anything", but I'll try.
So, your "DummyPanel" view have a alias or itemId property. In yor controller (in init() function), you need "keep track" of your view. For example:
In your view:
me.fireEvent('myEventName','Param1', fieldCollection, 'Param3');
In your controller:
init:function(){
var me = this;
this.control({
'panel[itemId=your-view-itemId]': { // call your function after event
myEventName: me.myControllerFunction
}
});
...
},
...
myControllerFunction: function(...) {
...
}
Should it not be
Ext.Msg.alert(collection["Order"])?
Or if you want to keep Ext.Msg.alert the way it is fieldCollection should be defined this way
var fieldCollection =
{
Order : 'ordNumber',
Ref : 'refNumber'
};

When using Extjs MVC,how to acquire the selections(CheckboxModel) in the controller?

Details:
In panel(View) I set selModel :
this.selModel = Ext.create('Ext.selection.CheckboxModel',{
listeners:{
selectionchange: function (sm,selections){
Ext.getCmp('removeButton').setDisabled(selections.length===0);
}
},
mode:'MULTI'
});
The target is delelte the item that was checked
In controller I wrote a func :
remove:function(){
var view = Ext.widget('userlist');
selection = view.selModel.getSelection();
var store = this.getUsersStore();
if(selection){
store.remove(selection);
store.sync();
}else{
alert('failed!');
}
}
I just can't acqurice the “selection”,anything wrong?
Ext.widget creates a new component, it is not a method to retrieve a reference to a previously created component.
There are several ways to get a reference, Ext.getCmp, Ext.ComponentQuery, or using refs in your controller config

unable to get the model attribute comparison result

In my backbone collection, this is the model data i have:
var student = [
{name:"student0",scored:75},
{name:"student1",scored:49},
{name:"student2",scored:25}
]
from the model data(collection), i am trying to get the 'scored' attribute more than 60...
To do this i use this method,
on click i am calling a method called 'showHighScore',
getHighSocre:function(){
return _.each(this.collection.models, function(item){
return parseInt(item.get('scored')) > 60
})
},
showHighScore:function(){
var highscore = this.getHighSocre();
console.log(highscore);//i am getting the result as undifined
}
when the 'showHighScore' called, i am looping and returning the values, but the console giving me a result as 'undefined'.. is this the way is wrong.. or what is the correct way to get the model collections which has the attribute 'scored' more than 60...
any one help me.. thanks in advance.
Try something like this:
var student = [
{name:"student0",scored:75},
{name:"student1",scored:49},
{name:"student2",scored:25}
];
var test = _.filter(student, function(item){ return item.scored > 60 });
console.log(test);
DEMO && CODE
For getting the json, you should use
var students = this.collection.toJSON();
Then return a new collection from the method, or refresh the current collection.

extjs buildquery override does not work

I created a gridfilter like this:
var filters = new Ext.ux.grid.GridFilters({filters: [
{type: 'string', dataIndex: 'ContactName'}
]});
I wish to override the buildquery method to provide custom logic.
When I do:
filters.buildQuery = function(filters){
alert(Ext.util.JSON.encode(this.store.baseParams.filterParams));
};
It works fine. But when I move the alert inside another function like this:
buildQuery1 : function(filters){
alert(Ext.util.JSON.encode(this.store.baseParams));
}
And call it like this:
filters.buildQuery = function(filters){
buildQuery1(filters);
};
The alert does not show. And I get this.store.baseParams is null or not an object.
I solved it like this:
filters.buildQuery = function(filters)
{
buildQuery1(this,filters);
};
AND:
buildQuery1 : function(scope,filters){ alert(Ext.util.JSON.encode(scope.store.baseParams)); }
Not sure why this works :)
I do not see all your code, however I got the impression that you are losing scope and mixing this with filters. To make sure what is in this call console.dir (this) and console.dir (filters) and see what object you have available

Resources