on 2021 Sep 10 3:01 AM
Hi,
I have a UI% select dropdown that I populate from a static JSON model. Can anyone point me to some documentation on how to change this to populate the JSON model from an MII Query Template please? I have spent days looking at forum sites and experimenting, but have not even come close to getting it to work.
My JSON code looks like this:
oSelect.setModel(new JSONModel({
selectedKey: "A2",
options: [{
key: "A1", text: "Peter" }, {
key: "A2", text: "Gill"}, {
key: "B1", text: "Harry"}, {
key: "B2", text: "Ralph"}, {
key: "C1", text: "Jack"}, {
key: "C2", text: "Jill"}, {
key: "D1", text: "Harry"}, {
key: "D2", text: "Sally"}
]
}));
Cheers, Alan
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem, another couple of ideas for you.
Combine your query and json conversion into a single transaction and just call the transaction. Or you could use a javascript library in your irpt such as XML2JSON. Or since you are using UI5 you could use an XML model rather than a JSON model - check this Blog.
Thanks
Kevin
Thanks Kevin, that gave me the final piece for the puzzle - setting path for the select binding to '/Rowsets/Rowset/0/Row' instead of '/options',
so my JSON instantiation became:
var my_Model = new sap.ui.model.json.JSONModel();
var my_URL = "/XMII/Illuminator?QueryTemplate=qryTemplateName&Content-Type=text/json&Param.1="+varParam1;
my_Model.loadData(my_URL, '', false, "POST");
and I add it to the Select object with:
oSelect.setModel(my_Model);
In case anyone stray across this question, here is my working solution, thanks to the guidance from Kevin and some other blogs.
.....
var my_Model = new sap.ui.model.json.JSONModel();
var my_URL = "/XMII/Illuminator?QueryTemplate=qryTemplateName&Content-Type=text/json&Param.1="+varParam1;
my_Model.loadData(my_URL, '', false, "POST");
.........
sap.ui.define(['sap/m/Select', 'sap/ui/core/Item', 'sap/ui/model/json/JSONModel'],
function (Select, Item, JSONModel) {
var oSelect = new Select({
selectedKey: 'keyvalue1',
items: {
path: '/Rowsets/Rowset/0/Row',
template: new Item({
key: '{keyFieldName}',
text: '{testFieldName}'
}),
},
change: function (oEvent) {
var selectedItem = oEvent.getParameter("selectedItem");
if (selectedItem) {
Selected_Text = selectedItem.getText();
Selected_Key = selectedItem.getKey();
alert(Selected_Key+'-'+Selected_Text);
}
}
});
oSelect.setModel(my_Model);
oSelect.placeAt('div1');
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.