语法错误:无法在“文档"上执行"querySelector":"[对象HTMLDocument]"不是有效的选择器 [英] SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLDocument]' is not a valid selector

查看:572
本文介绍了语法错误:无法在“文档"上执行"querySelector":"[对象HTMLDocument]"不是有效的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从显示模板上的共享点列表项中获取所有字段值,ctx.CurrentItem仅获取一些值,但不是我需要的全部.

I am trying to get all field values from a sharepoint list item on a display template, the ctx.CurrentItem only gets some values but not all I need.

我尝试了以下代码,但标题出现错误

I tried the following code, but I get the error on the title

SyntaxError:无法在文档"上执行"querySelector":"[对象 HTMLDocument]"是无效的选择器.

SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLDocument]' is not a valid selector.

function GetListItemById_Success(sender, args) 
{ 
   var id = ListItem.get_id(); 
   var title = ListItem.get_item("Title"); 
   alert("Updated List Item: \n Id: " + id + " \n Title: " + title); 
}

// Display an appropriate error message 
function GetListItemById_Fail(sender, args) 
{ 
   alert("GetListItemById Failed. \n" + args.get_message() + "\n" + args.get_stackTrace());
}

$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(CustomAction, "sp.js"); });

function CustomAction(){
var clientContext =  new SP.ClientContext.get_current();
var web = clientContext .get_web(); 
var targetList = clientContext.get_web().get_lists().getByTitle('Test Document Library');
var list = web.get_lists().getByTitle('Test Document Library'); 
ListItem = list.getItemById(ctx.CurrentItem.DocId);
clientContext.load(ListItem, "Id", "Title"); 
clientContext.executeQueryAsync(GetListItemById_Success, GetListItemById_Fail); 
}

推荐答案

升级位于顶级站点的jQuery后,我遇到了同样的异常.原因是引用了子站点主页中的旧jQuery库.

I got the same exception after upgrading jQuery located in top level site. The reason was reference to old jQuery library in subsite master page.

这篇关于语法错误:无法在“文档"上执行"querySelector":"[对象HTMLDocument]"不是有效的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆