let a = 'dafdsafasdfadgdafasfsagadfasfsafsadfsda';
let str = 'da';
let b = a.indexOf(str);
let i = 0;
let locationList = [];
let locationObj = {};
while(a.indexOf(str,i) !== -1){
locationObj = {};
locationObj.startNum = a.indexOf(str,i);
locationObj.endNum = a.indexOf(str,i) + str.length - 1
locationList.push(locationObj);
console.log("开始",i);
console.log("起始位置",a.indexOf(str,i));
console.log("结束位置",a.indexOf(str,i) + str.length - 1);
console.log("三种情况:1、选择位置在首位,2、选择位置在中间,3、选择位置在末尾");
i = a.indexOf(str,i) + str.length;
}
let d = a.split(str);
for(let i = d.length - 1;i >=0 ; i--){
if(i !== 0){
d.splice(i , 0 ,str);
}
}
if(d[0] === '') d.splice(0,1);
if(d[d.length - 1] === '') d.splice(d.length - 1,1);
console.log("c===================>", d);
let oneList = [];
let oneObj = {
};
for(let i = 0;i<d.length;i++){
oneObj = { }
if(d[i] === str){
oneObj.text = d[i];
oneObj.isSelect = true;
oneObj.isActive = false;
if(i !== 0) {
oneObj.startNum = locationList[oneList[i - 1].index].startNum
oneObj.endNum = locationList[oneList[i - 1].index].endNum
oneObj.index = oneList[i - 1].index + 1;
}
else {
oneObj.startNum = locationList[0].startNum
oneObj.endNum = locationList[0].endNum
oneObj.index = 1
}
}else{
oneObj.text = d[i];
oneObj.isSelect = false;
oneObj.isActive = false;
if(i !== 0) oneObj.index = oneList[i - 1].index;
else oneObj.index = 0
}
oneList.push(oneObj);
}
console.log("oneList=================>", oneList);