当调用该函数时,我得到一个“对象不支持此方法”错误
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();
});
答案 0 :(得分:0)
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。对于测试,您甚至可以使用cdn链接来实现jQuery和SPServices。
<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>