我是SharePoint的新手,我正在尝试使用JavaScript从SharePoint列表中读取数据。我创建了一个新的SP页面,并插入了内容编辑器Web部件。在内容编辑器中,我插入了以下代码。单击“保存”时,我看到的是代码本身,但看不到SP列表中的内容。如何使用JS从SP列表中读取数据?
<!DOCTYPE html>
<html>
<head></head>
<body></body>
<script>
var siteUrl = '/sites/MySiteCollection';
function retrieveListItems() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Announcements');
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);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nID: ' + oListItem.get_id() +
'\nTitle: ' + oListItem.get_item('Title') +
'\nBody: ' + oListItem.get_item('Body');
}
document.write(listItemInfo.toString());
//alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
</html>
答案 0 :(得分:0)
示例演示:
name = input("May I have your name? ")
age = int(input("Can I ask how old you are? "))
year = 2019
for age in range(age, 102, 2):
if age == 101:
age = 100
year -= 1
print("In {0} you will be {1} years old, {2}!".format(year, age, name))
year += 2