我有一個函數可以處理一些onChange
事件並且運行良好。該函數調用另一個函數來檢查單元格的內容,如果出現錯誤,它應該改變單元格的顏色。在handontable插件中不能使用的自定義渲染器函數
function Check(x, y)
{
var content = $editorTableContainer.handsontable('getDataAtCell', y, x);
var split = content.split(' ');
$.each(split, function (key, value) {
$.get('check.php?word=' + value, function (data) {
//blank if no error otherwise it returns an array of suggestions (only need to check if there is an error)
if (data) {
alert("test");
var meta = $editorTableContainer.handsontable('getCellMeta', y, x);
meta.renderer = ErrorRenderer;
}
});
});
return;
}
這裏是我的簡單ErrorRenderer:
function ErrorRenderer(instance, td, row, col, prop, value, cellProperties)
{
Handsontable.TextCell.renderer.apply(this, arguments);
console.log(row);
td.style.fontWeight = 'bold';
td.style.color = 'green';
td.style.background = '#CEC';
}
的ErrorRenderer不會被調用沉綿警報被觸發,任何想法,爲什麼?
謝謝
題外話:FWIW,有一個有用的JS代碼約定,以儲備只有構造函數的大寫函數名稱。 http://javascript.crockford.com/code.html#names – alxndr
謝謝。我不知道這 – Cornwell
看到我的評論關於在下面的答案渲染 – PostureOfLearning