const a = [
{'id': 1, 'name': 'Max'},
{'id': 2, 'name': 'Tom'},
{'id': 3, 'name': 'Max'},
{'id': 4, 'name': 'Max'}
];
let r = [...new Set(a.map(u => u.name))] // result ["Max", "Tom"]
Tag: set
[PDF.js] Set filename when downloading pdf
When using a blob or base64 data to open a file in PDF.js, the viewer is not able to get the correct filename. So when downloading the pdf using the download button inside the viewer, it will always download as document.pdf
. To manually set a filename, you can use the setTitleUsingUrl
function.
<iframe id="pdf-js-viewer" src="/pdf/web/viewer.html?file=" title="webviewer" frameborder="0" width="100%" height="700" allowfullscreen="" webkitallowfullscreen=""/>
let pdfViewerIFrame = document.getElementById("pdf-js-viewer")
pdfViewerIFrame.contentWindow.PDFViewerApplication.setTitleUsingUrl("myFilename")
More info here: https://github.com/mozilla/pdf.js/issues/10435
[SAPUI5] Get and set properties of a binded model and submit changes
Get:
const oModel = this.getView().getModel()
const sPath = this.getView().getBindingContext().sPath
const sID = oModel.getProperty(sPath+"/ID")
Set:
const newID = "12345"
oModel.setProperty(sPath+"/ID", newID)
When using the set property function, you can now submit your changes this way:
// First check if there are any changes
if (!oModel.hasPendingChanges()) {
MessageToast.show("Nothing to do!")
return
}
// Now submit your changes
oModel.submitChanges({
success: () => MessageToast.show("Success!"),
error: (err) => alert(err)
})
This way is much more comfortable, than using oModel.update()
.