查看是不是从其他控制器Appcelerator的合金更新 [英] View is not updating from other controller Appcelerator Alloy

查看:262
本文介绍了查看是不是从其他控制器Appcelerator的合金更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望你将被罚款。
我有钛铝合金Appcelerator的,

麻烦更新视图

我基本上希望从选择器能够删除previous孩子,然后在选择器是在不同的控制器/认为我目前在添加新的......

我跟了这<一个href=\"https://stackoverflow.com/questions/16062363/titanium-alloy-accessing-ui-from-different-controllers/16073970#16073970\"标题=该解决方案>这个解决方案可惜就是不为我工作。这里是code我想。

createEvent.js

  Ti.App.addEventListener('db_update',函数(){
   警报(OK);
   $ .picker.removeAllChildren();
})

customParty.js

  $。btnclick.addEventListener('点击',功能(){
    Ti.App.fireEvent('db_update');
});
 // OK警报显示出来,但选择器的孩子不会被删除。


解决方案

由于好吧警报显示,你在好的方法和回调函数调用成功。
这里的问题是,调用 removeAllChildren 方法不会从您选择器删除行。解决的办法是遍历colums和删除这种行:

  Ti.App.addEventListener('db_update',函数(){
   警报(OK);
   //获取选择器列
   。变种列= $ picker.getColumns();
   //迭代选择器列
   对于(VAR它= 0,长度= columns.length; I&LT;长度,它++){
        //遍历列行
        如果(列[它]){
             VAR LEN = col.rowCount;
             对于(VAR指数= 0,collength =列[它]。长度;指数&LT; collength;指数++){
                //删除列的行[指数] [它]
                列[它] .removeRow(列[它] .rows [指数]);
             }
        }
   }
});

顺便说一句Applcelerator的乡亲们说,使用全局事件(Ti.App事件)可能会导致内存管理层的问题...


  记

请该应用程序级事件是全球性的,这意味着他们仍然在上下文中的应用程序正在运行(除非你删除)的全部时间。这也意味着,他们引用任何对象,也将保持在范围上,而你的应用程序运行。这可能prevent这些对象被垃圾收集。<一个href=\"http://docs.appcelerator.com/platform/latest/#!/guide/Event_Handling-section-29004896_EventHandling-Application-LevelEvents\"相对=nofollow> Appcelerator的同性恋者的。


的另一种方法是使用全局函数:

在你的第一个视图控制器(其中选择器定义):

  Alloy.Globals.removeAllPickerChildren =功能(){
      //你想要的这里
};

然后在Seconde系列的ViewController:

  $。btnclick.addEventListener('点击',功能(){
    如果(Alloy.Globals.removeAllPickerChildren)
         Alloy.Globals.removeAllPickerChildren();
});

I hope you will be fine. I am having trouble updating views in Titanium Appcelerator Alloy,

I basically want to be able delete previous children from picker and then add new one in picker that is in a different controller/view that i am currently in.....

I have followed this THIS SOLUTION unfortunately that is not working for me. Here is the code I am trying.

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. 

解决方案

Since Ok Alert is shown, you are in the good way and the callback function is called successfully. The problem here is that calling removeAllChildren method is not removing rows from your picker. the solution is to iterate over colums and delete rows like this :

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's folks said that using global events (Ti.App events) may cause problems in memory managements...

Keep in mind that app-level events are global, which means they remain in context the entire time your app is running (unless you remove them). This also means that any objects they reference will also remain in scope while your app runs. This could prevent those objects from being garbage collected.Appcelerator gays.

Another method is to use global functions:

In your first view controller (where picker is defined):

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

then in the seconde viewcontroller:

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

这篇关于查看是不是从其他控制器Appcelerator的合金更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆