我已经实现了上面的plunker,在那个plunker中,rowId正在增加Alphabets。如下所示
该组件中将有+
和++
以及 - 按钮。
如果我按+
,那么The Rowid将从Starting Alphabet(A
)开始。
如果我按下++
那么父母rowid +从Starting Alphabet开始就意味着(AA
)。
再次,如果我按++
,那么从开始字母开始的父rowId +意味着(AAA
)。像这样会增加。
但我希望用Numbers表示实现该功能
对于单一加号,它应该显示1
,对于++
,它应该显示111
这样我需要实现的目标。
你能帮我做一下这个功能。
var newRow = {
"rowId": "A"
}
$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 + "A";
} 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 String.fromCharCode(inputChar.charCodeAt(0) + 1);
};
var getLastChar = function(fullStr) {
return fullStr.slice(-1);
};
答案 0 :(得分:2)