I am trying to make a select/dropdown option to select an available camera. I tried multiple ways I found in different solutions. Our company is using JS views, which makes it harder to find fitting solutions. Therefor, I hope this can help me out.
Code for getting available cameras, making a new array of object with only cameras using key and text to prepare for the select:
{
// ...
getCameras: function() {
var camList = [];
navigator.mediaDevices.enumerateDevices().then(function(inputs) {
inputs.forEach(function(input) {
if (input.kind === "videoinput") {
var camera = {
key: input.deviceId,
text: input.label
}
camList.push(camera);
}
});
});
return camList;
},
}
When im turning on the camera option I run this function:
{
// ...
setCameraSelect: function() {
var oController = sap.ui.getCore().byId('Row').getController();
var cameraModel = new sap.ui.model.json.JSONModel();
cameraModel.setData({ cameras: oController.getCameras() });
sap.ui.getCore().setModel(cameraModel, 'cameramodel');
cameraModel.refresh();
},
}
So far the model is loaded into the Core as cameramodel. Which I can also get back using:
var model = sap.ui.getCore().getModel("cameramodel");
console.log(model.oData);
Result: cameras: (2) [{…}, {…}]
In my view (JS), I got the following element:
var cameraSelect = new sap.m.Select("CameraSelect", {
items: {
path: "cameramodel>/cameras",
template: new sap.ui.core.ListItem({
key: "{cameramodel>key}",
text: "{cameramodel>text}"
})
},
});
I tried diffwrent versions of this, with and without the model name. Also tried to add the model to the element (sap.m.Select
) itself and use it, with and without naming it. But whatever I try the select, menu doesn't give any options.
What am I overseeing so badly?