我的jQuery出错,我不明白为什么......
我的错误:未捕获RangeError:超出最大调用堆栈大小
我的代码:
“getSelected”函数返回一个对象,“editeTextOfSelectedCase”更新“getSelected”对象......
var removeCaseToEditableMode = function removeCaseToEditableMode($case){
getSelectedCase().isEditable = false;
$case.attr('contenteditable', false);
$case.attr('id', '');
editeTextOfSelectedCase($case);
var $rightCase = getSelectedCase().$rightCase; // error with these two last lines ...
selectCase($rightCase);
};
编辑#2:
var getSelectedCase = function getSelectedCase(){
var $selectedCaseFound = false;
$.each(cases, function(index, value){
if( value.isSelected ){
$selectedCaseFound = value;
}
});
return $selectedCaseFound;
};
var editeTextOfSelectedCase = function editeTextOfSelectedCase($case){
getSelectedCase().preventText = getSelectedCase().newText;
getSelectedCase().newText = $case.text();
};
var selectCase = function selectCase($case){
unselectCase();
cases[$case.data('index')].isSelected = true;
setCssOfCase($case);
};
var unselectCase = function unselectCase(){
if( getSelectedCase() === false )
return false;
removeCssOfCase(getSelectedCase().$element);
removeCaseToEditableMode(getSelectedCase().$element);
cases[getSelectedCase().$element.data('index')].isSelected = false;
};
var setCssOfCase = function setCssOfClickedCase($case){
$case.addClass('selectedCase');
$case.addClass(params.class);
getSelectedCase().$topCase.addClass('pointer');
getSelectedCase().$rightCase.addClass('pointer');
getSelectedCase().$bottomCase.addClass('pointer');
getSelectedCase().$leftCase.addClass('pointer');
};
编辑#3:
var $this = $(this),
$cases = $this.find('td'),
cases = [],
_case = {};
$cases.each( function(index){
$this = $(this);
_case = {
$element: $this,
isSelected: false,
preventText: $this.text(),
newText: $this.text(),
caseNumbersInCurrentLine: $this.parent().find('td').length,
lineNumbersInCurrentCase: $this.parent().parent().find('tr').length,
index: $this.index(),
lineIndex: $this.parent().index(),
topIndexLine: $this.parent().index()-1,
topIndexCase: $this.index(),
rightIndexLine: $this.parent().index(),
rightIndexCase: ( $this.index() - $this.parent().find('td').length ) + 1,
bottomIndexLine: ( $this.parent().index() - $this.parent().parent().find('tr').length ) + 1,
bottomIndexCase: $this.index(),
leftIndexLine: $this.parent().index(),
leftIndexCase: $this.index()-1,
isEditable: false
};
_case.$topCase = $this.parent().parent().find('tr').eq(_case.topIndexLine).find('td').eq(_case.topIndexCase);
_case.$rightCase = $this.parent().find('td').eq(_case.rightIndexCase);
_case.$bottomCase = $this.parent().parent().find('tr').eq(_case.bottomIndexLine).find('td').eq(_case.bottomIndexCase);
_case.$leftCase = $this.parent().find('td').eq(_case.leftIndexCase);
cases.push(_case);
$this.data('index', index);
});