Javascript SharePoint使用查找下拉列表并获取值
我似乎在从下拉查找字段返回值时遇到了一些问题。我有以下代码,可以从我正在查找的列表中获取值:Javascript SharePoint使用查找下拉列表并获取值,javascript,sharepoint,lookup,dropdown,Javascript,Sharepoint,Lookup,Dropdown,我似乎在从下拉查找字段返回值时遇到了一些问题。我有以下代码,可以从我正在查找的列表中获取值: var siteUrl = _spPageContextInfo.webServerRelativeUrl; function getDropdownValues(tempNumTitle) { var clientContext = new SP.ClientContext(siteUrl); var tempDropdownValueList = clientContext.get
var siteUrl = _spPageContextInfo.webServerRelativeUrl;
function getDropdownValues(tempNumTitle) {
var clientContext = new SP.ClientContext(siteUrl);
var tempDropdownValueList = clientContext.get_web().get_lists().getByTitle('Temps');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View>' +
'<RowLimit>' +
'100' +
'</RowLimit>' +
'</View>');
this.tempQuery = tempDropdownValueList.getItems(camlQuery);
clientContext.load(tempQuery);
clientContext.executeQueryAsync(
// on success of getting Temp Values from dropdown
// match it with the tempNum entry
function (sender, args) {
var tempDropDownValues = {};
var tempEnumerator = tempQuery.getEnumerator();
while(tempEnumerator.moveNext()) {
var tempItem = tempEnumerator.get_current();
var tempTitle = tempItem.get_item('Title');
var tempId = tempItem.get_item('ID');
tempDropDownValues[tempTitle] = tempId;
}
selectTemp(tempNumTitle, tempDropdownValues)
},
// on failure
function (sender, args) {
console.info('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
);
}
var siteUrl=\u spPageContextInfo.webServerRelativeUrl;
函数getDropdownValues(tempNumTitle){
var clientContext=new SP.clientContext(siteUrl);
var tempDropdownValueList=clientContext.get_web().get_lists().getByTitle('Temps');
var camlQuery=new SP.camlQuery();
camlQuery.set_viewXml(“”+
'' +
'100' +
'' +
'');
this.tempQuery=tempDropdownValueList.getItems(camlQuery);
load(tempQuery);
clientContext.executeQueryAsync(
//从下拉列表中成功获取临时值
//将其与tempNum条目匹配
函数(发送方,参数){
var tempDropDownValues={};
var tempEnumerator=tempQuery.getEnumerator();
while(tempEnumerator.moveNext()){
var tempItem=tempEnumerator.get_current();
var tentitle=tempItem.get_item('Title');
var tempId=tempItem.get_item('ID');
tempDropDownValues[entitle]=tempId;
}
选择Temp(tempNumTitle、tempDropdownValues)
},
//论失败
函数(发送方,参数){
console.info('请求失败。'+args.get_message()+'\n'+args.get_stackTrace());
}
);
}
它执行得很好,给出了下拉值。然后,它调用函数selectTemp,其中包含我们要查找的tempNumTitle的参数以及检索到的下拉列表值。下面是下一个函数:
function selectTemp(tempNumTitle, tempValues) {
var clientContext = new SP.ClientContext(siteUrl);
var tempMatchValueList = clientContext.get_web().get_lists().getByTitle('Numbers-Temp');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View>' +
'<Query>' +
'<Where>' +
'<Eq>' +
'<FieldRef Name="Title" />' +
'<Value Type="Text">' + tempNumTitle + '</Value>' +
'</Eq>' +
'</Where>' +
'</Query>' +
'</View>');
this.tempMatchValueQuery = tempMatchValueList.getItems(camlQuery);
clientContext.load(tempMatchValueQuery);
clientContext.executeQueryAsync(
// on success
function (sender, args) {
var temp = '';
tempEnumerator = tempMatchValueQuery.getEnumerator();
while(tempEnumerator.moveNext()) {
var tempItem = tempEnumerator.get_current();
temp = tempItem.get_item('Temp0');
}
},
// on failure
function (sender, args) {
console.info('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
);
}
函数selectTemp(tempNumTitle,tempValues){
var clientContext=new SP.clientContext(siteUrl);
var tempMatchValueList=clientContext.get_web().get_lists().getByTitle('Numbers-Temp');
var camlQuery=new SP.camlQuery();
camlQuery.set_viewXml(“”+
'' +
'' +
'' +
'' +
''+tempNumTitle+''的+
'' +
'' +
'' +
'');
this.tempMatchValueQuery=tempMatchValueList.getItems(camlQuery);
load(tempMatchValueQuery);
clientContext.executeQueryAsync(
//论成功
函数(发送方,参数){
var temp=“”;
tempEnumerator=tempMatchValueQuery.getEnumerator();
while(tempEnumerator.moveNext()){
var tempItem=tempEnumerator.get_current();
temp=tempItem.get_item('Temp0');
}
},
//论失败
函数(发送方,参数){
console.info('请求失败。'+args.get_message()+'\n'+args.get_stackTrace());
}
);
}
它几乎让我得到了我想要的东西,但我得到了这样的东西:
温度:{$1E_1:3,$2e_1:“温度3”}
这里我想要$2e_1的值,或者“Temp 3”。我如何才能获得该值,而不只是进入temp[“$2e_1”]?当访问查找列或人员选择器列时,列值是复杂类型而不是简单字符串 您可以对返回的对象调用
.get\u lookupValue()
,以获取查找列值的文本表示形式,或者调用.get\u lookupId()
以获取查找列表(或者在人员选取器列的情况下,在网站集的用户信息列表中)中相应项的ID号
因此,在您的情况下,假设“Temp0”是查找列的内部名称,您应该能够执行以下操作:
temp = tempItem.get_item('Temp0').get_lookupValue();
访问查找列或人员选择器列时,列值是复杂类型,而不是简单字符串 您可以对返回的对象调用
.get\u lookupValue()
,以获取查找列值的文本表示形式,或者调用.get\u lookupId()
以获取查找列表(或者在人员选取器列的情况下,在网站集的用户信息列表中)中相应项的ID号
因此,在您的情况下,假设“Temp0”是查找列的内部名称,您应该能够执行以下操作:
temp = tempItem.get_item('Temp0').get_lookupValue();
非常感谢你。就这样。我只是不知道。get_lookup__();常规,或者看起来不够努力。你太棒了!非常感谢你。就这样。我只是不知道。get_lookup__();常规,或者看起来不够努力。你太棒了!