下面的代码在我的其他项目中工作得很好,但是当我在当前项目中将对象放置到div中时,它会弹出此错误。对于placeAt()方法有什么必须注意的问题吗?
rest.then(function(response){
var dataset = response.data;
array.forEach(dataset, function(single, i){
if(dataset[i].favorite){
favorite++;
}
if(dataset[i].status == "OO"){
outOfService++;
}
});
try{
var dashBoardShortCutCell = new DashBoardShortCutCell();
dashBoardShortCutCell.construct("favorite", favorite);
dashBoardShortCutCell.placeAt(context.shortCutContainerNode);
}catch(err){
console.log(err);
}
dashBoardShortCutCell = new DashBoardShortCutCell();
dashBoardShortCutCell.construct("Out of Service", outOfService);
try{
dashBoardShortCutCell.placeAt(context.shortCutContainerNode);
}catch(err){
console.log(err);
}
}, function(err){
console.log("Error", err);
}, function(evt){
});
控制台显示:
DashboardPage.js:85 TypeError: Cannot read property 'style' of null(…)
DashboardPage.js:95 TypeError: Cannot read property 'style' of null(…)
"无法读取属性'style'为null"
从错误本身已经提到的根本原因。您的JavaScript正在尝试对未定义/空节点进行一些样式化。请确保您正确定义了目标节点