open new window for every selected element in a multiselect list?

时间:2018-06-04 16:58:26

标签: javascript sapui5

I'm trying to open new windows depending on selected items in a multiselect list, but I'm getting no result, it only opens one window, always the first one selected, even if there are two or more.

here is the code I have so far:

    var oModelPrint = new sap.ui.model.json.JSONModel(docImprimir);
    var oList = new List({
        mode: 'MultiSelect',
        items: {
            path: '/Items',
            template: new sap.m.StandardListItem({
                title: '{text}',
                selected: '{selected}'
            })
        }
    });
    oList.setModel(oModelPrint);
    var dialog = new sap.m.Dialog({
        title: 'Imprimir Documento',
        type: 'Message',
        content: [
            oList
        ],
        beginButton: new Button({
            text: 'Imprimir',
            press: function(oEvent) {
                var valorItemSelected = oList.getSelectedItem();
                var numItems = oList.getSelectedItems().length;
                var oObject = valorItemSelected.getBindingContext().getObject();
                var key = oObject.key;
                var navigationService = sap.ushell.Container.getService('CrossApplicationNavigation');

                var i = 1;

                 //Here is where i have the issue
                for (i = i; i <= numItems; i++) {

                var hash = navigationService.hrefForExternal({
                    target: {
                        semanticObject: 'zrefiopdf01Sem',
                        action: 'display'
                    },
                    params: {
                        DocNumber: document,
                        Formtype: key
                    }
                });

                var url = window.location.href.split('#')[0] + hash;
                sap.m.URLHelper.redirect(url, true);

                }

any idea how can I do this?

2 个答案:

答案 0 :(得分:0)

use window.open(*url*)

The demo below will work in general, but it doesn't here because it's sandboxed to StackOverflow.

let btn = document.getElementById("btn");
btn.addEventListener("click", function(e) {
let g = document.getElementById("google"), b = document.getElementById("bing");
if(g.checked) window.open("http://www.google.com/");
if(b.checked) window.open("http://www.bing.com/");

});
<input id="google" type="checkbox">
<input id="bing" type="checkbox">

<button id="btn">Open</button>

https://codepen.io/zfrisch/pen/eKZOgB is a live example.

Keep in mind that typically more than one window opening will be blocked by a popup blocker.

答案 1 :(得分:0)

You will need to disable your browser's popup blocker for your site (and ask your users to do the same).

Most modern browsers' popup blockers (including the one built into Chrome) work on the basis of "one click, one window". Scripts are only allowed to open windows while handling user inputs (e.g, while running an onclick handler), and are only allowed to open one window during a given event handler. Your script is violating this rule, and every window after the first one is being blocked.