View is not updated from another Adcelerator Alloy controller

I hope everything will be all right with you. I'm having trouble updating my views in the Titanium Appcelerator Alloy,

Basically I want to remove the previous child elements from the collector, and then add a new one to the collector, which is in another controller / view in which I now ...

I followed this THIS SOLUTION , unfortunately, this does not work for me. Here is the code I'm trying to do.

createEvent.js

Ti.App.addEventListener('db_update', function(){ alert("OK"); $.picker.removeAllChildren(); }) 

customParty.js

 $.btnclick.addEventListener('click', function(){ Ti.App.fireEvent('db_update'); }); // OK alert shows up but the children of picker aren't removed. 
+1
source share
1 answer

Since Ok Alert is shown, you are in good condition and the callback function is called successfully. The problem is that calling the removeAllChildren method does not remove rows from your collector. the solution is to iterate over the columns and delete the rows as follows:

 Ti.App.addEventListener('db_update', function(){ alert("OK"); //get picker columns var columns=$.picker.getColumns(); //Iterate over picker columns for (var it=0,length=columns.length;i<length;it++){ //iterate over column rows if(columns[it]){ var len = col.rowCount; for(var index=0,collength=columns[it].length;index<collength;index++){ //remove rows[index] of columns[it] columns[it].removeRow(columns[it].rows[index]); } } } }); 

By the way, Applcelerator people said that using global events (Ti.App events) could cause memory management problems ...

Keep in mind that application-level events are global, which means that they remain in context all the time your application is running (unless you delete them). This also means that all the objects that they reference also remain in the application scope. This may interfere with the collection of these objects. Heroes of Appellier .

Another method is to use global functions:

In your first view controller (where the collector is defined):

 Alloy.Globals.removeAllPickerChildren=function(){ //do what you want here }; 

and then in the second view of the viewcontroller:

 $.btnclick.addEventListener('click', function(){ if(Alloy.Globals.removeAllPickerChildren) Alloy.Globals.removeAllPickerChildren(); }); 
0
source

All Articles