Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 复制/粘贴时Flex spark TextArea限制最大字符数_Apache Flex_Textarea_Max_Flex Spark - Fatal编程技术网

Apache flex 复制/粘贴时Flex spark TextArea限制最大字符数

Apache flex 复制/粘贴时Flex spark TextArea限制最大字符数,apache-flex,textarea,max,flex-spark,Apache Flex,Textarea,Max,Flex Spark,我搜索了一下,没能找到。我们有一个带有maxChars=“3900”的Spark文本区域。但当复制/粘贴到文本区域时,它不起作用。我试着把这个添加到changingHandler中: if (ta.text.length > 3900) { Alert.show("The maximum characters length is 3900. Please limit the characters to the max lim

我搜索了一下,没能找到。我们有一个带有maxChars=“3900”的Spark文本区域。但当复制/粘贴到文本区域时,它不起作用。我试着把这个添加到changingHandler中:

 if (ta.text.length > 3900)
        {
                        Alert.show("The maximum characters length is 3900. Please limit the characters to the max limit");
                        ta.text = ta.text.substr(0, 3900);
                    } else 
                    {
                        if (event.operation is PasteOperation)
                        {
....//Other logic
                        }
       }
问题是它不是一直有效。该警报仅在超过3900个字符时显示几次。不知道为什么。我还向changeHandler添加了同样的内容。但这根本不会被触发

请让我知道我错过了什么。我需要显示一个警报&每次超过最大限制时,将字符修剪到最大值

谢谢


Harish

首先,我们需要清除一件事:当触发更改处理程序时,这意味着:文本正在更改,但更改尚未应用

如果textare中的文本为“”(空),现在,我粘贴1600个字符,调用更改处理程序,文本的长度仍然为0,因为它正在更改,而不是更改

现在,如果你有一个变更处理程序,当你追踪长度时,它应该是1600

但是,如果在更改方法中使用“event.preventDefault();”,并且不更改更改处理程序中的文本,则不应触发更改处理程序

因此,我的建议是:

  • 使用更改处理程序是正确的
  • 在处理程序中,获取剪贴板中的文本,然后您可以获取剪贴板中文本的长度,使用此长度+textArea.text.length,您将获得粘贴处理后的长度。 如果总长度大于您的限制,您可以阻止事件,并做任何您想做的事情 以下是一些代码:

    protected function textArea_changingHandler(event:TextOperationEvent):void
            {
                trace(event.type + " - " + textArea.text.length); //  this length is befor the paste
    
                if(event.operation is PasteOperation) {
                    // Text in the clipboard.
                    var textPaste:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT) == null ? "" : Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT) as String; 
                    // this length is after the paste(if the paste will complete)
                    var totalLength:int = textArea.text.length + textPaste.length; 
                    trace("String length after Paste: " + totalLength);
    
                    if(totalLength > 3900) {
                        event.preventDefault();
                        textArea.text += "[Paste:" + textPaste.substr(0, 2) + "]"; // process your text here. 
                    }
                }
            }
    

    它不起作用了怎么办?你收到错误了吗?还是意外的行为?请提供详细信息。我有一个文本数为1600的word文档。我复制/粘贴了3次,但没有触发警报。然后,当我试图复制文本区域中的文本时,它决定显示警报&他们修剪文本!奇怪的我还不清楚问题出在哪里。听起来好像一切都像您预期的那样正常工作?在处理程序方法中,在if块之前,尝试跟踪您的文本字符串长度。@davidligoliang我试过了。我认为问题在于,当我第一次粘贴1600个字符时,它会显示textArea.length=0。当我第二次粘贴同一块时,现在它显示为length=1600(实际上是3200)。因此,当大小>3900时,它不会抛出警报。你知道为什么会这样吗?