开发者

Setting a property list with Titanium Appcelerator

I'm working with the latest Mobile SDK (1.6) on OS X. I have this piece of code:

var globalArray = [
        {title:'foo',value:'yes'},
        {title:'bar',value:'no'}
]; 

Titanium.App.Properties.setList('globalArrayProperty',globalArray);
Titanium.App.Properties.getList('globalArrayProperty')[0].value = 'it works!';
Titanium.API.info('first value : ' + Titanium.App.Properties.getList('globalArrayProperty')[0].value);

I simplified it so that I can explain you where the problem stands. So, I create an array with a couple of objects. Then, I'm setting a property depending on this array and then affecting a开发者_高级运维 new value to the first object. But when I call the display the property, instead of showing the 'it works!' string, it shows the initial one 'yes'.

I tried by adding a couple of lines:

Titanium.App.Properties.setList('globalArrayProperty',globalArray);
var arr = Titanium.App.Properties.getList('globalArrayProperty');
arr[0].value = 'it works!';
// This works
Titanium.API.info('first value with arr: ' + arr[0].value);
// This doesn't work
Titanium.API.info('first value : ' + Titanium.App.Properties.getList('globalArrayProperty')[0].value);

So the intermediate var 'arr' get the property, set it but cannot apply the modification on the property.

Am I missing something?

Thanks,

Regards.


i think you need to set the property list again after updating the array

Titanium.App.Properties.setList('globalArrayProperty',globalArray);
var arr = Titanium.App.Properties.getList('globalArrayProperty');
arr[0].value = 'it works!';
// This works
Titanium.API.info('first value with arr: ' + arr[0].value);

// save changes to property list
Titanium.App.Properties.setList('globalArrayProperty',arr);

// This doesn't work
Titanium.API.info('first value : ' + Titanium.App.Properties.getList('globalArrayProperty')[0].value);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜