0
votes

Does anyone know how to remove selected items from an array?

var view:NotesView = getComponent("viewPanel2");
var UtbildningarArray = new Array();
viewScope.col = view.getSelectedIds();
if (viewScope.col.length > 0){
for (i=0; i<viewScope.col.length; i++){
    var docid = viewScope.col[i];
        if (docid != null) {
            var doc = database.getDocumentByID(docid);
            UtbildningarArray.push(doc.getItemValueString("Namn"))
        }
    }
}
document1.removeItemValue("Utbildningar",UtbildningarArray);
document1.save();

I have tried, removeEntry and splice but I don't get it work.

Thanks, Jonas

Edit:

You are right, have added this in the code:

var view:NotesView = getComponent("viewPanel2");
var UtbildningarArray = new Array();
var UtbildningarArray = new Array();
var FieldUtbArray = new Array(getComponent('inputHidden1').getValue());

viewScope.col = view.getSelectedIds();
if (viewScope.col.length > 0){
    for (i=0; i<viewScope.col.length; i++){
        var docid = viewScope.col[i];
            if (docid != null) {
                var doc = database.getDocumentByID(docid);
                UtbildningarArray.push(doc.getItemValueString("Namn"))
            }
        }
    }

document1.replaceItemValue("Utbildningar",FieldUtbArray.slice(UtbildningarArray));
document1.save();

I'm saving what the user selected in a hidden input, and when the user clicks the "Remove programs" button I display the selected courses in the view. Then should the user be able to click a checkbox and remove the selected course(s). Now when I save nothing happens.

2

2 Answers

1
votes
1
votes

I got it work!

for (var i = 0; i < FieldUtbArray.length; i++) {
    found = false;
    // find a[i] in b
    for (var j = 0; j < UtbildningarArray.length; j++) {
        if (FieldUtbArray[i] == UtbildningarArray[j]) {
            found = true;
            break;
        }
    }
    if (!found) {
        result.push(FieldUtbArray[i]);
    }
}