2016-07-06 97 views
0

p1 p2 的选项,这是我的js代码:我怎么可以重写选择2

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

我希望 “& NBSP;”在p1中可以像解析p2那样使用select2。其他人给出的数据为 ,所以我无法更改它。那么,我如何 重写select2的选项。任何提示都会有帮助。 Thx很多 多!

+0

适用于选择2 –

回答

0

更新:

你应该移动& NBSP选项“孩子”,看到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); 
    } 
+0

这是非常有用之前,你必须“干净”的数据,但结果没有关...空间丢失 –

+0

其实,我想select2来解析' '作为html占位符 –

+0

我已经更新了我的答案。 –