【问题标题】:'this' undefined in chrome, but works in IE'this' 在 chrome 中未定义,但在 IE 中有效
【发布时间】:2013-08-01 04:27:29
【问题描述】:

下面,该功能在 IE 中工作,这很好,但我还需要它在 Chrome、FireFox 等中工作...... 在 Chrome 中我遇到错误...这是我的代码

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);

...它在 Chrome 中说...“未捕获的 TypeError:无法设置未定义的属性 'collListItem'..

我假设这是来自“this”.. chrome 处理 'this' 和 ie 处理 'this' 的方式有区别吗??

对此我能做些什么?谢谢!

【问题讨论】:

    标签: javascript sharepoint sharepoint-2013 csom


    【解决方案1】:

    由于某些草率的连接等原因,您的代码非自愿(或故意?)处于严格模式下,这意味着没有显式接收器的函数调用将 undefined 放置为 this 值而不是全局对象。较旧的 IE 无法识别严格模式,因此它会像以前一样继续工作。

    只需将this 更改为window

    有趣的事实:这发生在amazon too

    【讨论】:

      猜你喜欢
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-11
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多