如何更新钛全局变量? [英] how to update global variable in titanium?

查看:117
本文介绍了如何更新钛全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这里是我的代码:

  Ti.App.dinercolor = [#FF5A00,#007EFF,#dccdc0,#C2FF95,#A700FD,#dccdc0 #dccdc0, #5F9EA0, #dccdc0, #dccdc0, #22A000, #dCCDC0, #dccdc0, #FF003C, #dccdc0, #FF003C , #dccdc0, #22A000, #dccdc0, #FFF191]; 

这就是我的全局数组,它可以从应用程序的任何位置访问数据。



当我想更新数组时,问题出现了:

  for(var q = 0; q   

所以,我期待的数组在操作完成之后就是这样的:

  Ti.App.dinercolor = [ #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0\" , #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0, #dccdc0\" , #dccdc0]; 

但是不知何故,我得到的是更新后的相同阵列,

  Ti.App.dinercolor = [#FF5A00,#007EFF,#dccdc0,#C2FF95,#A700FD,# dccdc0\" , #dccdc0, #5F9EA0, #dccdc0, #dccdc0, #22A000, #dCCDC0, #dccdc0, #FF003C, #dccdc0,# FF003C, #dccdc0, #22A000, #dccdc0, #FFF191]; 

请帮助我,我不知道我在这里做错了什么,



谢谢,

解决方案

您的代码是正确的,但您不应该扩展Ti对象,因为这样会出现意想不到的事情。创建你自己的对象,它会工作。

  myObj = {}; 
myObj.dinercolor = [];

等等。

它是建议您将应用程序保存在一个上下文中,以便您可以从任何地方访问该对象。查看锻造钛视频系列,了解一些最佳做法。

i'm having some problem in updating my array which is global by the way.

here is my code:

Ti.App.dinercolor=["#FF5A00","#007EFF","#dccdc0","#C2FF95","#A700FD","#dccdc0","#dccdc0","#5F9EA0","#dccdc0","#dccdc0","#22A000","#DCCDC0","#dccdc0","#FF003C","#dccdc0","#FF003C","#dccdc0","#22A000","#dccdc0","#FFF191"];

thats my global array which i can access data from it from anywhere in the application.

the problem comes when i want to update the array like:

for(var q=0; q<Ti.App.dinercolor.length; q++){Ti.App.dinercolor[q] = '#dccdc0';}    

so, the array i was expecting after the operation thats done is something like this:

Ti.App.dinercolor=["#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0","#dccdc0"];

but somehow i'm getting the same array with out updating,

Ti.App.dinercolor=["#FF5A00","#007EFF","#dccdc0","#C2FF95","#A700FD","#dccdc0","#dccdc0","#5F9EA0","#dccdc0","#dccdc0","#22A000","#DCCDC0","#dccdc0","#FF003C","#dccdc0","#FF003C","#dccdc0","#22A000","#dccdc0","#FFF191"];

please help me out, i have no idea what i'm doing wrong here,

Thank you,,

解决方案

Your code is correct, but you shouldn't extend the Ti object as unexpected things like this will happen. Create your own object and it will work.

myObj = {};
myObj.dinercolor = [];

And so on.

It is recommended you keep your app in a single context so you will be able to access the object from anywhere. Check out the forging titanium video series for some best practices.

这篇关于如何更新钛全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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