日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Sharepoint学习笔记—ECMAScript对象模型系列-- 7、获取和修改List的Lookup字段

發布時間:2025/4/16 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Sharepoint学习笔记—ECMAScript对象模型系列-- 7、获取和修改List的Lookup字段 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在前面我們提到了如何使用ECMAscript對象模型來操作普通的List Items,但如果我們操作的List包含有Lookup字段,那么我們又該怎么做呢?
首先參考此文搭建我們本文的測試環境
Sharepoint學習筆記---SPList--創建一個帶有Lookup字段的List

一、對于獲取操作,我們使用如下代碼

<script?type="text/javascript">
????function?GetLookupValue()?{
????????var?context?=?new?SP.ClientContext.get_current();
????????var?web?=?context.get_web();
????????var?list?=?web.get_lists().getByTitle('TestSale');
????????var?query?=?SP.CamlQuery.createAllItemsQuery();
????????allItems?=?list.getItems(query);
????????context.load(allItems,?'Include(ProductName,LookupStaffName)');
????????context.executeQueryAsync(Function.createDelegate(this,?this.successGetLookupValue),
???????????????????????????Function.createDelegate(this,?this.failedGetLookupValue));
????}

????function?successGetLookupValue()?{
????????var?TextFiled?=?"";
????????var?ListEnumerator?=?this.allItems.getEnumerator();
????????while?(ListEnumerator.moveNext())?{
????????????var?currentItem?=?ListEnumerator.get_current();
????????????TextFiled?+=?currentItem.get_item('ProductName')?+?'-'?+?currentItem.get_item('LookupStaffName').get_lookupValue()?+?'\n';
????????}
????????alert(TextFiled);
????}

????function?failedGetLookupValue(sender,?args)?{
????????alert("failed.?Message:"?+?args.get_message());
????}

</script>

效果如下:

二、對于修改操作,我們使用如下代碼

<script?type="text/javascript">
????function?SetLookupValue()?{
????????var?context?=?new?SP.ClientContext.get_current();
????????var?web?=?context.get_web();
????????var?list?=?web.get_lists().getByTitle('TestSale');
????????var?query?=?SP.CamlQuery.createAllItemsQuery();
????????allItems?=?list.getItems(query);
????????context.load(allItems,?'Include(ProductName,LookupStaffName)');
????????context.executeQueryAsync(Function.createDelegate(this,?this.successSetLookupValue),?Function.createDelegate(this,?this.failedSetLookupValue));
????}
????function?successSetLookupValue()?{
????????var?TextFiled?=?""
????????var?ListEnumerator?=?this.allItems.getEnumerator();
????????while?(ListEnumerator.moveNext())?{
????????????var?currentItem?=?ListEnumerator.get_current();
????????????var?newLookupField?=?new?SP.FieldLookupValue();
????????????
????????????newLookupField.set_lookupId(2)??//Updated?with?some?lookup?value?for?LookupStaffName?column
????????????????????????????????????????????//?Here?is?an?id?of?your?lookup?list?item?'Steve';
????????????currentItem.set_item('LookupStaffName',?newLookupField);
????????????currentItem.update();
????????????//?Call?context.executeQueryAsync?again
????????}
????}
????function?failedSetLookupValue(sender,?args)?{
????????alert("failed.?Message:"?+?args.get_message());
????}

</script>

?效果如下:

?

需要說明的是,在修改中,我們使用到代碼

newLookupField.set_lookupID(2)

此代碼中參數的含意就是從LookupItem所綁定的數據源List中去取值,如下圖:


轉載于:https://www.cnblogs.com/wsdj-ITtech/archive/2012/06/06/2418912.html

總結

以上是生活随笔為你收集整理的Sharepoint学习笔记—ECMAScript对象模型系列-- 7、获取和修改List的Lookup字段的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。