【问题标题】:Get all textFields value from titanium从钛中获取所有 textFields 值
【发布时间】:2016-07-04 08:59:32
【问题描述】:

我已经从一个对象动态创建了文本字段:

var fields = [{field:'telephone', hint:'Telephone'},{field:email, hint:'Email} ... ];

并创建字段:

 _.each(fields, function(item){
    var field = Ti.UI.createTextField({
        id : item.field,
        hintText : item.hint,
    });
    $.form.add(field)

})

我创建了一个按钮:

var button = Ti.UI.createButton({
    title : 'Send All'
});
$.form.add(button)

现在我想在单击按钮时将所有 textFields 值存储到全局对象中。

var output = [];
$.button.addEventListener(function(){
    /* I want to loop to each created textFields above and get value from id */
    _.each(fields, function(item){
        output.push(item.value);
    });
    Alloy.Globals.form = output;
});

但这不起作用,单击按钮时我无法获取已创建字段的值。 请问您知道如何处理吗?

谢谢

【问题讨论】:

    标签: titanium appcelerator-titanium appcelerator-mobile


    【解决方案1】:

    你可以通过 children 属性来获取它

    例如

    $.button.addEventListener(function(){
        _.each($.form.children, function(item){
           if(item.apiName == "Ti.UI.TextField"){   
            output.push(item.value);
          }
    });
    Alloy.Globals.form = output;
    });
    

    【讨论】:

    • 您好,谢谢您的回复,这似乎是一个好方法,我只有一个问题:事件字段是动态创建的,我可以通过 $.form.children 获取主题吗?非常感谢
    • 是的,您将通过 children 属性获得它,不管它是动态的还是静态的。
    猜你喜欢
    • 2019-06-28
    • 1970-01-01
    • 2011-08-09
    • 2018-04-03
    • 2015-08-22
    • 2019-05-16
    • 2017-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多