如何重写 select2 的选项

How can I rewrite option of select2

这是我的js代码:

function getCompany(){
         var url = _reqCtx + "/extReport/getCompany.action";
         function callback(response){
          $("#searchForm").find("#companyId").select2({
           data : response
          });
         };
         $.post(url,{},callback);
        }

我想要“ ”在 p1 中可以解析 space 就像 p2 使用 select2。这 数据是别人给的,我改不了。那么,我怎样才能 重写 select2 的选项。任何提示都会有所帮助。非常感谢 很多!

更新:

您应该将   选项移动为 "children",参见 jsfiddle

function getCompany(){
        var url = _reqCtx + "/extReport/getCompany.action";
        function callback(response){
            nested_data = [];
            // PSEUDO CODE
            for (line in data){
               if line has &nbsp then
               Replace &nbsp and move them into children property
            }
            // END OF PSEUDO CODE

            $("#searchForm").find("#companyId").select2({
                data : nested_data
            });
        };
        $.post(url,{},callback);
    }