Question

below, the function works in IE, which is Good, but I need it to work in Chrome, FireFox, etc as well... In Chrome Im getting an Error... Heres my code

function loadList(list_name) {
    var oList = context.get_web().get_lists().getByTitle(list_name);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);

... it says in Chrome.. "Uncaught TypeError: Cannot set property 'collListItem' of undefined..

I am assuming this is from the "this" .. is there a difference on how chrome handles 'this' and ie handles 'this'??

What can I do about this ? Thank you!

Était-ce utile?

La solution

Your code is involuntarily (or deliberately?) under strict mode due to some sloppy concatenation or such, this means function calls without explicit receiver place undefined as this value instead of the global object. Older IEs don't recognize the strict mode so it keeps working like it has before.

Just change this to window.

Fun fact: this has happened to amazon too

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top