0

我不知道 JavaScript,但我需要在我的公司 Intranet 上使用 SPServices。我需要将 fieldNames 写入页面上的一些 div 中,我该怎么做?这是 SPServices 脚本:

<script type="text/javascript">
$( document ).ready(function(){
var thisUsersValues = $().SPServices.SPGetCurrentUser({
fieldNames: ["FirstName", "LastName", "Picture", "JobTitle", "WorkPhone", "WebSite",],
debug: false
});
</sript>

谢谢!

4

3 回答 3

0
var thisUsersValues = $().SPServices.SPGetCurrentUser({
    fieldNames: ["FirstName", "LastName"], 
    debug: false
});

var name = thisUsersValues.FirstName + " " + thisUsersValues.LastName;
alert('Your name: ' + name);

我对此进行了测试,这是正确的用法。只需使用“。” 语法,或者您可以使用thisUserValues['FirstName'];andthisUserValues['LastName'];来检索属性。

从那里,Cana 发布的另一个答案是正确的:

var userDescription = "<div>" + name + "</div>";
var obj = $("#someObjId").append(userDescription);
于 2016-01-25T20:38:49.527 回答
0

我知道这是旧的(我是该站点的新手),但这是基于您的 JavaScript 使用 DOM 的另一种选择。它将 currentuser 拉到一个变量中,并使用 DOM 插入到div. 这也适用于输入字段。注意图片的 .src。

<script type="text/javascript" language="javascript">
$(document).ready(function() {
    var userdetails = $().SPServices.SPGetCurrentUser(
    {
        fieldNames: ["ID","EMail","UserName","FirstName","LastName","Picture","JobTitle","WorkPhone","Office"],
        debug:false
    });

    document.getElementById('NameExample').innerHTML = (userdetails.FirstName + " " + userdetails.LastName);
    document.getElementById('PhotoExample').src = (userdetails.Picture);
    document.getElementById('EmailExample').innerHTML = (userdetails.EMail);
    document.getElementById('TitleExample').innerHTML = (userdetails.JobTitle);
    document.getElementById('OfficePhoneExample').innerHTML = ("Office" + " " +   userdetails.WorkPhone);
    document.getElementById('nameInputField').value = (userdetails.FirstName + " " + userdetails.LastName);
    document.getElementById('emailInputField').value = (userdetails.EMail);
    document.getElementById('OfficePhoneField').value = (userdetails.WorkPhone);
    document.getElementById('titleInputField').value = (userdetails.JobTitle);
});
</script>

<div>
    <span id="OfficePhoneExample"></span></br>
    <span id="EmailExample"></span></br>
</div>
于 2016-09-13T21:40:07.810 回答
-1

也许这可以帮助你:

var $userDescription = "<div>"+ thisUsersValues.toString() +"</div>";
$("#yourDivID").append($userDescription);
于 2013-06-11T12:26:43.627 回答