在基于在排序依据本plunker NG-重复它工作正常,但是当ROWID超过父+
按钮9号,其rowid变得10
。
父行rowid 10
显示为1
的子项。
在这里我分开父母和子女与-
。 如果rowid是小孩,那么我在儿童记录之前添加-
。 最后我想实现的是我想要显示10
作为父母,1-10
作为孩子。
var newRow = {
"rowId": "1",
"componentIdentification": "",
"componentName": "",
"codigo": "",
"componentType": "",
"componentState": "",
"actionId": "",
"actionPerform": ""
}
$scope.componentList = [];
$scope.componentList.push(angular.copy(newRow));
$scope.addParentRow = function(rowId) {
var newGridRow = angular.copy(newRow);
var lastChar = getListOfSameLevel(rowId, true); //isParentRow
var parentId = rowId.length > 1 ? rowId.slice(0, rowId.length - 1) : "";
newGridRow.rowId = parentId + getNextChar(lastChar);
$scope.componentList.push(newGridRow);
}
$scope.addChildRow = function(rowId) {
var newGridRow = angular.copy(newRow);
var lastChar = getListOfSameLevel(rowId, false);
if (rowId.length === lastChar.length) {
newGridRow.rowId = rowId + "-1";
} else {
var parentId = lastChar.length > 1 ? lastChar.slice(0, lastChar.length - 1) : "";
newGridRow.rowId = parentId + getNextChar(getLastChar(lastChar));
}
$scope.componentList.push(newGridRow);
};
var getNextChar = function(inputChar) {
return parseFloat(inputChar) + 1;
};
var getLastChar = function(fullStr) {
return fullStr.slice(-1);
};
var getListOfSameLevel = function(rowId, isParentRow) {
var compIdLength = rowId.length;
var matchedArray = [];
var sortedMatchedArray = [];
var latestCompId = "";
if (compIdLength > 1) {
var parentId = isParentRow ? rowId.slice(0, rowId.length - 1) : rowId;
if (!isParentRow) {
matchedArray = _.filter($scope.componentList, function(row) {
return ((row.rowId.length >= compIdLength) && row.rowId.startsWith(parentId));
});
} else {
matchedArray = _.filter($scope.componentList, function(row) {
return ((row.rowId.length === compIdLength) && row.rowId.startsWith(parentId));
});
}
sortedMatchedArray = matchedArray.sort();
latestCompId = sortedMatchedArray[sortedMatchedArray.length - 1].rowId;
return isParentRow ? getLastChar(latestCompId) : latestCompId;
} else {
matchedArray = _.filter($scope.componentList, function(row) {
return (row.rowId.length === compIdLength || (!isParentRow && row.rowId.startsWith(rowId)));
});
sortedMatchedArray = matchedArray.sort();
latestCompId = sortedMatchedArray[sortedMatchedArray.length - 1].rowId;
return latestCompId;
}
};
再次相同的代码! – anu
代码是相同的但问题不同 – Murali
@Murali,这是因为你的id是一个字符串,而不是一个数字 – devqon