我想从以下SP.FieldLookupValue对象中获取值,即$ 1E_1存储值“karanataka” 输出:
SP.FieldLookupValue
$1E_1:"KARNATAKA"
__proto__:Object
调试时:
projectNumberLookup = SP.FieldLookupValue {$1E_1: "KARNATAKA"}
以下是我的代码示例:
var projectNumberLookup = new SP.FieldLookupValue();
var projLookupId = listItemState;
projectNumberLookup.set_lookupId(projLookupId);
我尝试使用以下内容访问该值:
var s=projectNumberLookup.$1E_1;
newItem.set_item('State',projectNumberLookup.$1E_1);
newItem.set_item('State',projectNumberLookup.get_lookupValue ());
newItem.set_item('State',projectNumberLookup.get_lookupId ());
没有任何效果。可以有人建议解决方案
答案 0 :(得分:0)
使用如下所示的get_lookupValue和get_lookupId函数从查找字段中获取值:
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getLookUp, 'sp.js');
var oListItem
function getLookUp()
{
var clientContext = SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var webSite = clientContext.get_web();
var list = webSite.get_lists().getByTitle("NewList");
oListItem = list.getItemById(1);
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
}
function OnLoadSuccess(sender, args) {
// for multiple value lookup field
var multiplevaluelookup = oListItem.get_item("TabletopSessions");
console.log(multiplevaluelookup);
for(var i = 0;i < multiplevaluelookup.length;i++)
{
console.log(multiplevaluelookup[i].get_lookupId());
console.log(multiplevaluelookup[i].get_lookupValue());
}
//for single value lookup field
var singlevaluelookup = oListItem.get_item("LookupSingleValue");
console.log(singlevaluelookup.get_lookupId());
console.log(singlevaluelookup.get_lookupValue());
}
function OnLoadFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>