我遇到的问题只出现在chrome中,并且在firefox中运行正常,没有任何问题
computedStyle = getComputedStyle(element, ':before');
content = computedStyle.getPropertyValue('content').slice(1, -1);
// content --> NULL
matchResult = content.match(/^\s*(\d+)(?:\s?\.(.+))?\s*$/);
if (matchResult) {
numberOfColumns = matchResult[1];
columnClasses = ((_ref = matchResult[2]) != null ? _ref.split('.') : void 0) || ['column'];
} else {
matchResult = content.match(/^\s*\.(.+)\s+(\d+)\s*$/);
columnClasses = matchResult[1]; // <-- Error here
numberOfColumns = (_ref1 = matchResult[2]) != null ? _ref1.split('.') : void 0;
}
return {
numberOfColumns: numberOfColumns,
columnClasses: columnClasses
};
};
add_columns = function(grid, items) {
var columnClasses, columnsFragment, columnsItems, i,
并且控制台中的错误是Uncaught TypeError: Cannot read property '1' of null
答案 0 :(得分:0)
// ...
if (matchResult) {
numberOfColumns = matchResult[1];
columnClasses = ((_ref = matchResult[2]) != null ? _ref.split('.') : void 0) || ['column'];
} else if (matchResult = content.match(/^\s*\.(.+)\s+(\d+)\s*$/)){
columnClasses = matchResult[1]; // <-- Error here
numberOfColumns = (_ref1 = matchResult[2]) != null ? _ref1.split('.') : void 0;
} else {
columnClasses = numberOfColumns = null;
}
// ...
在处理数据之前,请确保matchResult
不为空。