Вопрос

I am using the below code to insert an item into the list.

  function createitem() {
var selectListBox = document.getElementById("txtFormName");
var selectedListTitle = selectListBox.value;
var selectedList = web.get_lists().getByTitle(selectedListTitle);

var listItemCreationInfo = new SP.ListItemCreationInformation();
var newItem = selectedList.addItem(listItemCreationInfo);

newItem.set_item('Title','abc');
newItem.update();
context.load(newItem);
context.executeQueryAsync(onItemCreationSuccess, onItemCreationFail);

}

Its working fine. Now I want to use

    newItem.set_item('Title1','def');
    newItem.set_item('Title2','xyz');
    .
    .
    .
    and so on

in loop for more than one item in the same row to insert. How can i achieve that. kindly guide.

Это было полезно?

Решение

You can use a loop as follows

var selectListBox = document.getElementById("txtFormName");
var selectedListTitle = selectListBox.value;
var selectedList = web.get_lists().getByTitle(selectedListTitle);

for(var index = 0; index < 10; index++) {
    var listItemCreationInfo = new SP.ListItemCreationInformation();
    var newItem = selectedList.addItem(listItemCreationInfo);
    newItem.set_item('Title' + index.toString(),'abc'+ index.toString());
    newItem.update();
}

context.load(selectedList);
context.executeQueryAsync(onItemCreationSuccess, onItemCreationFail);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top