2017-02-03 28 views
0

您好我正在從webservice獲取像這些多個記錄列表。只顯示在HTML使用angularjs的有限文本

  1. cn=HOUW-MAR-LVL1,cn=Chola MS Organization structure,cn=cordys,cn=devInst2,o=chol

  2. cn=SUW-COM-NONMOT-LVL1-TN1,cn=Chola MS Organization Structure,cn=cordys,cn=devInst2,o=cholamandalamins.com

我只想顯示HOUW-MAR-LVL1SUW-COM-NONMOT-LVL1-TN1即第一=,之間的文本。

是否有可能來處理,在HTML或angularJS

回答

0

如果格式總是XX =,那麼你可以使用普通的JavaScript字符串/數組的方法來得到你所需要的。

var originalString = "cn=HOUW-MAR-LVL1,cn=Chola MS Organization structure,cn=cordys,cn=devInst2,o=chol" 

//First split the string at each comma 
var arrayOfStrings = originalString.split(",") 

//Now use map to go through the array one string at a time 
var trimmedStrings = arrayOfStrings.map(function(stringToTrim) { 
//Trim the characters up to and including the equals sign 
    return stringToTrim.substring((stringToTrim.indexOf("=") + 1), stringToTrim.length); 
}); 

//Result = trimmedStrings 

["HOUW-MAR-LVL1","Chola MS Organization structure","cordys","devInst2","chol"] 

每個單獨的修剪串可以通過它的索引號

訪問