更改 ListView 模板内 TextField 上的事件 [英] Change event on TextField inside ListView Template

查看:45
本文介绍了更改 ListView 模板内 TextField 上的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView 模板,它有一个标题标签、2 个按钮视图(或多或少)和一个带值的 TextField,我需要向这个 TextField 添加一个更改事件.

I've a ListView Template, that has a title Label, 2 button Views (more and less) and a TextField with a value, I need to add a change event to this TextField.

<ItemTemplate name="item" id="item" bindId="item">
    <View id="row" bindId="row">
        <Label bindId="title" id="title"/>
        <View id="options" bindId="options">
            <View class="option" bindId="less" id="less"/>
            <TextField bindId="input" id="input"/>
            <View class="option" bindId="more" id="more"/>
        </View>
    </View>
</ItemTemplate>

在更改事件中,我想添加一个验证来检查值是否是这样的数字:

In the change event I want to add a validation to check if the value is a number like this:

$.input.value = parseFloat(($.input.value.toString().replace(/,/g, '.')).replace(/[a-zA-Z ,_$#%&()~ºª´`'+*:;]/g,''));

越来越少的按钮正在工作,它是一个简单的递增/递减,但我无法将侦听器添加到输入中,我已经尝试了这两种方法:

The less and more buttons are working, its a simple increment/decrement, but I can't add the listener to the input, I've tried this 2 ways:

$.car.addEventListener('itemclick',function(list) {

    var row = $.car.sections[0].getItemAt(list.itemIndex);

    if(list.bindId == 'more') row.input.value++;
    if(list.bindId == 'less') row.input.value--;

    //tried this 1#: row.input.addEventListener('change',function() {});

    $.car.sections[0].updateItemAt(list.itemIndex,row);
});

//tried this 2#: $.input.addEventListener('change',function() {});

请注意,我只需要在单击行时使用侦听器,每次更改输入值或使用其中一个按钮时,我都知道 ListItem 的索引

Note that I only need to use the listener when the row is clicked, every time that I change the input value or use one of the buttons, I know the index of the ListItem

推荐答案

我不知道这是否是最好的方法,但我会尝试创建一个隐藏的 TextField,当我单击 ListItem 的 TextField 时,模糊隐藏的文本字段,并且在更改事件上它将使用相同的值更新 ListItem 的文本字段

I don't know if it's the best approach, but what I'll try is to create an hidden TextField, when I click the ListItem's TextField, blur the hidden TextField, and on the change event it will update the ListItem's TextField with the same value

这篇关于更改 ListView 模板内 TextField 上的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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