gpt4 book ai didi

javascript - SP 服务 - 对象不支持此方法

转载 作者:行者123 更新时间:2023-11-28 08:19:49 25 4
gpt4 key购买 nike

调用该函数时,我收到“对象不支持此方法”错误

function LoadCat(cat) {

if (cat != null) {
var liHtml = "Category: <select name=\"categoryselect\" id=\"categoryselect\">";
var CAML = '<Query><Where><Eq><FieldRef Name="Department" /><Value Type="Text">' + cat + '</Value></Eq></Where></Query>';
alert(CAML);
} else {
alert(cat);
var CAML = '';
}




$().SPServices({
operation: "GetListItems",
async: false,
webURL: "http://sp-app",
listName: "Categories",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQuery: CAML,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
liHtml = liHtml + "<option value=''>" + $(this).attr("ows_Title") + "</option>";

});
liHtml = liHtml + "</select>";
$("#cat").html(liHtml);
}

});
}

错误出现在 $().SPServices({ line

当 cat 为 null 或有值时,就会发生这种情况。

几个小时以来我一直在摸索这个问题!

SharePoint 服务在调用该函数之前加载!

似乎只有当我在此函数上调用它时才会发生错误:

  $(".area").click(function () {


$(".area").parent("li").removeClass("active");
$(this).parent("li").addClass("active");

LoadCat();

});

最佳答案

function LoadCat(cat) {
if (cat != null) {
var liHtml = "Category: <select name=\"categoryselect\" id=\"categoryselect\">";
var CAML = '<Query><Where><Eq><FieldRef Name="Department" /><Value Type="Text">' + cat + '</Value></Eq></Where></Query>';
alert(CAML);
} else {
alert(cat);
var CAML = '';
}

$().SPServices({
operation: "GetListItems",
async: false,
webURL: "http://sp-app",
listName: "Categories",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQuery: CAML,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
liHtml = liHtml + "<option value=''>" + $(this).attr("ows_Title") + "</option>";

});
liHtml = liHtml + "</select>";
$("#cat").html(liHtml);
}

});}
$(document).ready(function() {
var subject = "Hi Subject!";
var message = "Hi Message!";
LoadCat(subject);
});

查看浏览器中的 JavaScript 控制台,您可以在其中找到有用的错误。必须加载 jQuery 和 SPServices。对于您的测试,您甚至可以使用 jQuery 和 SPServices 的 cdn 链接。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>

关于javascript - SP 服务 - 对象不支持此方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23129324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com