【问题标题】:Grid not rendering in firefox网格不在Firefox中呈现
【发布时间】:2013-06-14 11:40:50
【问题描述】:

我正在使用EditableGrid 动态生成和操作列模型。一切都按计划进行,除了与 Firefox 的一个兼容性问题(..是的,不是 IE -_-)。我知道这可能是某种关闭问题?我似乎无法解决这个问题。这就是问题所在:

EditableGrid.prototype.initializeGrid = function () {
    with (this) {
        //apply cell validators and inforenderers in headers
        var regex = [];
        for (var count = 0; count < selectedColumnNames.length; ++count) {
            var columnObj = findSelectedColumnObject(selectedColumnNames[count]);

            //check if regex is provided
            if (!(columnObj[0].validationRegex == "")) {
                // add a cell validator
                var expression = new RegExp(columnObj[0].validationRegex);
                regex[columnObj[0].name] = new RegExp(columnObj[0].validationRegex);
                var valObj = GetValidatorObject(expression);
                addCellValidator(columnObj[0].name, valObj);
            }
        }

        function GetValidatorObject(regObj){
            var obj = {
                isValid: function (value) {
                    return value == "" || (regObj.test(value));
                }
            };
            return new CellValidator(obj);
        }
}

它抛出的异常是:

ReferenceError: GetValidatorObject 未定义 [var valObj = GetValidatorObject(表达式);]

有什么想法吗?

【问题讨论】:

  • 吹毛求疵,避免with!使用它只会让您头疼不已。我猜这就是你出错的原因。
  • 我不明白,为什么是FF?它与其他浏览器完美兼容?
  • 当我将GetValidatorObject 移出with(this) 的范围时它可以工作

标签: javascript jquery editablegrid


【解决方案1】:

感谢epascarello,解决方法很简单,我将GetValidatorObject的方法移出with (this)的范围。现在它适用于FF。当我进一步深入研究此事时,我发现avoid using 'with' keyword in JS 真的很有趣。这可能会清除灰色区域。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 2012-12-19
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多