You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CKEditor从Word粘贴脚本错误求助(PrimeFaces扩展版)

Fixing "Cannot read property 'map' of undefined" in PrimeFaces Extensions CKEditor + Paste from Word

Hey there, let's work through this paste error you're seeing with PrimeFaces Extensions' CKEditor 4.6 and Paste from Word 4.9.2. That Cannot read property 'map' of undefined trace points to a missing array in the Word cleanup logic—here are some actionable steps to resolve it:

Possible Solutions

  • Align plugin versions for compatibility
    Paste from Word 4.9.2 is newer than your CKEditor 4.6 instance, which can lead to mismatched expectations in data structures. Try downgrading the Paste from Word plugin to a version that matches CKEditor 4.6's release (e.g., 4.6.x). This often fixes missing variable issues caused by API changes between versions.

  • Debug the failing getCompareFunction
    The error originates in getCompareFunction at line 935 of default.js.xhtml. This function is likely trying to call map() on a variable that should be an array but is undefined. You can add a quick debug check here (temporarily, for testing) to see what's missing:

    function getCompareFunction(a) {
      // Add this line to log the problematic variable
      console.log('Expected array:', a);
      return function(b, c) { /* ... existing logic ... */ }
    }
    

    This will show you if the style rules or formatting data from the Word paste isn't being parsed correctly.

  • Disable conflicting plugins
    Other CKEditor plugins (custom or built-in) might interfere with the Paste from Word cleanup process. Try disabling non-essential plugins one by one, especially those that modify paste events or content formatting, to isolate the conflict.

  • Implement a custom paste handler
    If the built-in CKEDITOR.cleanWord is failing, you can pre-process the paste data before the default cleanup runs. Add this to your editor initialization:

    CKEDITOR.replace('yourEditorId', {
      // Your existing config
      on: {
        paste: function(evt) {
          var rawData = evt.data.dataValue;
          // Add custom cleanup here to fix malformed content
          // Example: Remove any unrecognized style blocks that might break the parser
          evt.data.dataValue = rawData.replace(/<unrecognized-tag[^>]*>/g, '');
        }
      }
    });
    

    Run this handler before the default one by setting a lower priority (use the fourth parameter in on() if needed).

  • Upgrade PrimeFaces Extensions
    PrimeFaces Extensions 6.1.1 is quite outdated. Updating to a newer version (that supports CKEditor 4.6 or later) might include fixes for this exact compatibility issue with the Paste from Word plugin.

Error Details (for reference)

Uncaught TypeError: Cannot read property 'map' of undefined
at getCompareFunction (default.js.xhtml?ln=primefaces-extensions&v=6.1.1:935)
at sort (default.js.xhtml?ln=primefaces-extensions&v=6.1.1:956)
at Object.inline (default.js.xhtml?ln=primefaces-extensions&v=6.1.1:977)
at Object.CKEDITOR.cleanWord (default.js.xhtml?ln=primefaces-extensions&v=6.1.1:57)
at eval (eval at (jquery.js.xhtml?ln=primefaces&v=6.0:14), :997:253)
at l (eval at (jquery.js.xhtml?ln=primefaces&v=6.0:14), :995:294)
at a.eval (eval at (jquery.js.xhtml?ln=primefaces&v=6.0:14), :997:98)
at a.m (eval at (jquery.js.xhtml?ln=primefaces&v=6.0:14), :10:224)
at a.eval (eval at (jquery.js.xhtml?ln=primefaces&v=6.0:14), :12:47)
at a.CKEDITOR.editor.CKEDITOR.editor.fire (eval at (jquery.js.xhtml?ln=primefaces&v=6.0:14), :13:242)

内容的提问来源于stack exchange,提问作者Udaya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:19:23