Appcelerator:可以检测 textArea 中的@mention

Appcelerator: Possible to detect @mention in textArea

所以我成功地设置了一个很好的 textArea 来获取用户输入,该输入将 post 到我创建的 Web 表单中。我想向文本区域添加 @mention 功能,这样如果用户键入 @somename,在他们键入时它将查询 JSON 网络服务以提取可能的名称匹配的一些值。

我的第一个出发点是以某种方式检测 textArea 中的变化以查看用户是否试图@mention 某人

关于如何处理这个问题有什么想法或想法吗?

谢谢!

要检测文本区域的变化,您可以使用 change 事件。以下代码将有助于开始工作:

var textArea = Ti.UI.createTextArea({
    borderWidth: 2,
    borderColor: '#bbb',
    borderRadius: 5,
    color: '#888',
    font: {fontSize:20, fontWeight:'bold'},
    textAlign: 'left',
    value: 'I am a textarea',
    top: 60,
    width: 300, height : 70
});
textArea.addEventListener("change", textAreaValueChanged);

function textAreaValueChanged() {
    var newTextAreaValue = textArea.value;
    // now parse this newTextAreaValue according to your need and hit webservice
}