按照上一个问题here,
我有一个桌面应用程序,使用 Electron 平台和Javascript,我正在使用以下方法将HTML5画布转换为JPEG:
function download(){
var dt = canvas.toDataURL('image/jpeg');
this.href=dt;
}
document.getElementById('download').addEventListener('click', download, false);
然后,
NSMutableDictionary *resultDic = [NSMutableDictionary new];
for (int i = 0; i < arrayChildModel.count; i++)
{
ChildModel *model = [arrayChildModel objectAtIndex:i];
NSString *keyOrder = [NSString stringWithFormat:@"Children_Gender[%d]",i];
NSString *keyQuantity = [NSString stringWithFormat:@"Children_BirthDate[%d]",i];
NSString *keyTobacco = [NSString stringWithFormat:@"Children_HasTobaccoUsage[%d]",i];
//NSString *keyNotes = [NSString stringWithFormat:@"row[%d][description]",i];
childDateOfBirthStr = model.ChildBirthDate ;
childGenderStr = model.ChildGender ;
childTobaccoStr = model.ChildTobaccoUsage;
NSString *string1 = [NSString stringWithFormat:@"%@=%@&",keyOrder,childGenderStr];
NSString *string2 = [NSString stringWithFormat:@"%@=%@",keyQuantity,childDateOfBirthStr];
NSString *string3 = [NSString stringWithFormat:@"%@=%@",keyTobacco,childTobaccoStr];
[stringParams appendString:string1];
[stringParams appendString:string2];
[stringParams appendString:string3];
NSDictionary * ChildDict = [NSDictionary dictionaryWithObjectsAndKeys:childGenderStr,@"Child_Gender",childDateOfBirthStr,@"Child_DOB",childTobaccoStr,@"Child_tobbacoUse", nil];
NSLog(@"Dictionary is %@",ChildDict);
NSString *resultDicKey = [NSString stringWithFormat:@"%d",i+1];
[resultDic setValue:ChildDict forKey:resultDicKey];
}
NSLog(@"Result dic %@",resultDic);
这会刷新我的整个申请。如何更改此行为,以便在单击下载属性时不刷新页面?
答案 0 :(得分:3)
我可以想到这两个片段,一个使用blob,一个使用下载元素。外部图书馆:FileSave.js
// this one use FileSaver.js library
canvas.toBlob(function(blob) {
saveAs(blob, "pretty image.png");
});
// or this way using download element.
// here you can encode your image-data and then send it.
var download = document.getElementById('download');
download.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(imageData));
download.setAttribute('download', 'file.jpg');
我刚刚发现这个,电子特定的解决方案: Saving files locally with electron
答案 1 :(得分:1)
稍微编辑你的锚标记
clip(0,0.49999,0,100)
abline(lm(score ~ demvoteshare, data = subset(Lee, demvoteshare <= 0.5)), col="red")
clip(0.5,1,0,100)
abline(lm(score ~ demvoteshare, data = subset(Lee, demvoteshare > 0.5)), col="green")
然后是你的下载功能
lines(lowess(Lee$demvoteshare, Lee$score, f = 2/3, delta = 0.01*1), col="red")
这可能会有所帮助