问题描述
var objContext = null;
var objWeb = null
var objList = null;
var objItem = null;
函数deleteUser(){
var tid = document.getElementById('tid' ).value;
alert(tid);
objContext = new SP.ClientContext.get_current();
objWeb = objContext.get_web();
objList = objWeb.get_lists()。getByTitle(PeopleProfile);
var query = new SP.CamlQuery();
query.set_viewXml('< view>< query>< where> ;< eq>< fieldref name =LinkTitle>'+
'< value type =Text>'+ tid +'');
this.collListItems = objList.getItems(query);
objContext.load(collListItems);
objContext.executeQueryAsync(Function.createDelegate(this,this.onSuccess),Function.createDelegate(this,this.onFail));
}
函数onSuccess(发件人,args){
var listItemEnumerator = this.collListItems.getEnumerator();
while(listItemEnumerator.moveNext()){
var oListItem = listItemEnumerator.get_current();
var iid = oListItem.get_id();
alert(iid);
delet(iid);
}
}
function delet(d){
this.lstObjectItem = objList.getItemById(d);
alert(d);
this.lstObjectItem.deleteObject();
// clientContext.load(this.lstObjectItem);
objContext.executeQueryAsync(Function.createDelegate(this ,this.onSuccessDel),Function.createDelegate(this,this.onFailDel));
}
函数onSuccessDel(sender,args){
警报('项目已删除');
}
函数onFailDel(发件人,args){
alert('发生了一些错误。');
}
函数onFail(发件人,args){
alert('发生了一些错误'。 );
}
当我执行此代码的某个时候某个项目被删除时
var objContext = null;
var objWeb = null
var objList = null;
var objItem = null;
function deleteUser() {
var tid = document.getElementById('tid').value;
alert(tid);
objContext = new SP.ClientContext.get_current();
objWeb = objContext.get_web();
objList = objWeb.get_lists().getByTitle("PeopleProfile");
var query = new SP.CamlQuery();
query.set_viewXml('<view><query><where><eq><fieldref name="LinkTitle">' +
'<value type="Text">' + tid + '');
this.collListItems = objList.getItems(query);
objContext.load(collListItems);
objContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
}
function onSuccess(sender, args) {
var listItemEnumerator = this.collListItems.getEnumerator();
while(listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var iid = oListItem.get_id();
alert(iid);
delet(iid);
}
}
function delet(d){
this.lstObjectItem = objList.getItemById(d);
alert(d);
this.lstObjectItem.deleteObject();
// clientContext.load(this.lstObjectItem);
objContext.executeQueryAsync(Function.createDelegate(this, this.onSuccessDel), Function.createDelegate(this, this.onFailDel));
}
function onSuccessDel(sender, args) {
alert('Item deleted');
}
function onFailDel(sender, args) {
alert('Some error occured.');
}
function onFail(sender, args) {
alert('Some error has occured.');
}
when i am executing this code sometime item is deleted some time not
推荐答案
function CallDelFunc() {
ExecuteOrDelayUntilScriptLoaded(deleteUser, "sp.js");
}
function deleteUser() {
/* do some thing here*/
}
<input type="button" value="Delete" onclick="CallDelFunc();" />
或者您可以使用SP.SOD.executefunc而不是CallDelFunc函数内的ExecuteOrDelayUntilScriptLoaded直接加载函数
or you can load the function directly by using SP.SOD.executefunc instead of ExecuteOrDelayUntilScriptLoaded inside the CallDelFunc function
SP.SOD.executeFunc("sp.js", "SP.ClientContext", deleteUser);
这篇关于在哪里使用ExecuteOrDelayuntilScriptLoaded(deleteUser," sp.js");在这的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!