Titanium 保留在文本字段中输入的数据

Titanium 保留在文本字段中输入的数据,titanium,Titanium,我的情况是,我希望保留/保存文本字段中输入的数据,并且在单击文本字段时,将创建我以前输入的数据的下拉列表,并且如果我关闭并打开应用程序,输入的数据仍将在下拉列表中。例如,我在文本字段中输入了“abc123”,然后按下按钮上的enter键,它将在文本字段的下拉列表中保存“abc123”,如果我退出应用程序并再次输入,“abc123”仍将在下拉列表中 var win = Ti.UI.createWindow({ backgroundColor: 'white', }); var txtfield

我的情况是,我希望保留/保存文本字段中输入的数据,并且在单击文本字段时,将创建我以前输入的数据的下拉列表,并且如果我关闭并打开应用程序,输入的数据仍将在下拉列表中。例如,我在文本字段中输入了“abc123”,然后按下按钮上的enter键,它将在文本字段的下拉列表中保存“abc123”,如果我退出应用程序并再次输入,“abc123”仍将在下拉列表中

var win = Ti.UI.createWindow({
backgroundColor: 'white',
});

var txtfield = Ti.UI.createTextField({
});

var btn = Ti.UI.createButton({
title: 'go'
});

win.add(btn);
win.add(txtfield);
win.open();

明确建议使用sessionStorage或localStorage,您需要将值保存到SQLite或Ti.App.Properties

以下是一个工作示例:

var win = Ti.UI.createWindow({
    backgroundColor : 'white',
    layout : 'vertical'
});

var txtfield = Ti.UI.createTextField({
    width : Ti.UI.FILL,
    height : Ti.UI.SIZE,
    hintText : 'Enter new values...',
    top : 0
});

var picker = Ti.UI.createPicker({
    top : 10
});

var data = (Ti.App.Properties.hasProperty('itemList')) ? Ti.App.Properties.getList('itemList') : [];
Ti.API.info('data is ' + data);
var m = [];
if (data)
data.forEach(function(item) {

    m.push(Ti.UI.createPickerRow({title:item}));

});
Ti.API.info('M is ' + m);
if (m.length > 0)
picker.add(m);

var btn = Ti.UI.createButton({
top : 10,
width : Ti.UI.SIZE,
height : Ti.UI.SIZE,
title : 'go'
});

btn.addEventListener('click', function(e) {
var s = [];
if (Ti.App.Properties.hasProperty('itemList')) {
    Ti.API.info('Property found');
    s = Ti.App.Properties.getList('itemList');
}
Ti.API.info('S is ' + s);
s.push(txtfield.value);
Ti.App.Properties.setList('itemList', s);
picker.add(Ti.UI.createPickerRow({title:txtfield.value}));
txtfield.value = '';
});

win.add(btn);
win.add(txtfield);
win.add(picker);
win.open();

谢谢你,海尼!这很好,但如果我只想将picker替换为下拉列表,就像这个图像移动控件不同于桌面控件,Tianium没有现成的下拉列表,如果你想要一个,你需要从Scratch创建它,这意味着我必须使用view、scrollbar逐个创建,等等?@Emmanuel:你可以创建自己的下拉列表。因为移动设备没有这样的控制。您可以使用textField和tableView来执行此操作