SP.SOD.executeFunc('sp.js',
'SP.ClientContext', function(){
var ctx=new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle("TVC");
ctx.load(list);
ctx.executeQueryAsync(Function.createDelegate(this, function(){
console.log("List ID= "+list.get_id().toString());
console.log("List Item Count= "+list.get_itemCount());
}), Function.createDelegate(this, function(){}));
});
var ctx=new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle("TVC");
ctx.load(list);
ctx.executeQueryAsync(Function.createDelegate(this, function(){
console.log("List ID= "+list.get_id().toString());
console.log("List Item Count= "+list.get_itemCount());
}), Function.createDelegate(this, function(){}));
});
Code to get all list fields
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
var ctx=new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle("TVC");
var listFields = list.get_fields();
ctx.load(listFields);
ctx.executeQueryAsync(Function.createDelegate(this, function(){
var listEnumerator = listFields.getEnumerator();
while (listEnumerator.moveNext()) {
var oField = listEnumerator.get_current();
var fType = oField.get_fieldTypeKind();
if(fType === SP.FieldType.choice) {
}
oField.get_staticName() ? title=oField.get_staticName() :title='';
console.log(title);
}
}), Function.createDelegate(this, function(){}));
});
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
var ctx=new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle("TVC");
var listFields = list.get_fields();
ctx.load(listFields);
ctx.executeQueryAsync(Function.createDelegate(this, function(){
var listEnumerator = listFields.getEnumerator();
while (listEnumerator.moveNext()) {
var oField = listEnumerator.get_current();
var fType = oField.get_fieldTypeKind();
if(fType === SP.FieldType.choice) {
}
oField.get_staticName() ? title=oField.get_staticName() :title='';
console.log(title);
}
}), Function.createDelegate(this, function(){}));
});
SharePoint 2010
ExecuteOrDelayUntilScriptLoaded is not working reliably in Chrome. It
does work reliably in IE, however..
Even a simple example
like:
SP.SOD.executeOrDelayUntilScriptLoaded(blah,
"SP.js");
function blah(){
alert('!');
}
does not work reliably
when the page is loaded. It will *sometimes* work with a complete page
refresh. But this is unacceptable when using SP javascript API for web-facing
applications..
I discovered something
that seems to have fixed the issue for me.
My master page has the
following
<body scroll="no" onload="if
(typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();" class="v4master">
I found that if I used
the in-browser script console and called _spBodyOnLoadWrapper(), the scrollbars
would be added properly to my window and the SOD functions would work properly
again.
It seems to me that
the body onload is not being called reliably in Chrome. I'm not sure what could
be causing this, as the onload event seems to be fired reliably on a very
simple html page when trying to reproduce the issue.
Since I am using
jQuery anyway, I pulled the code from the body onload and instead used a jQuery
document ready method to call this:
<script type="text/javascript">
$(document).ready(function(){
if (typeof(_spBodyOnLoadWrapper)
!= 'undefined')
{
_spBodyOnLoadWrapper();
}
});
</script>
and now my body tag
looks like this:
<body scroll="no" class="v4master">
No comments:
Post a Comment