我有这个please try below code.
-(UIImage *)getMainImageFromContext
{
UIGraphicsBeginImageContextWithOptions(viewBG.bounds.size, viewBG.opaque, 0.0);
[viewBG.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
首先检查属性是否存在然后将其删除。然后,如果未在forEach
中定义该属性,则会再次使用新值附加该属性。它看起来像这样:
existingParams
问题是它永远不会删除一个参数parameters = parameters || {};
let existingParams = this.getUrlParameters();
_.forEach(parameters, function (value, key) {
if ((value !== null || typeof value !== 'undefined')
&& existingParams.hasOwnProperty(key)
) {
//First console.log
console.log("Deleted!: " + existingParams[key])
delete existingParams[key];
return;
} else if (value === null || typeof value === 'undefined') {
return;
}
//Second console.log
console.log(existingParams);
if ( ! existingParams.hasOwnProperty(key)) {
Object.defineProperty(existingParams, key, {
value: value,
enumerable: true,
configurable: true
});
return;
}
existingParams[key] = value;
});
(第一个if语句)。在第一个console.log中,我看到正在删除正确的param。但是在第二个console.log中,param仍在那里!?!?!?
这怎么可能?
existingParams 例如:delete existingParams[key];
参数例如:{minPrice: "1021", maxPrice: "2751", page: 1}