<Field
ID="{3ae962b5-7f82-4a22-a966-83a0694570ee}"
Name="Region"
DisplayName="Region"
Type="Lookup"
Required="true"
Group="Contoso Columns"
List="Lists/Regions"
ShowField="RegionName"///这个是供查阅的List:Regions
>
</Field>
///VS新建一个网格栏 改掉需要的属性。新建一个供于查阅的List我建了一个名叫Regions
<Data>
<Rows>
<Row>
<Field Name="Title">地区1</Field>
<Field Name="RegionName">Asia</Field>
</Row>
<Row>
<Field Name="Title">地区2</Field>
<Field Name="RegionName">Europe</Field>
</Row>
<Row>
<Field Name="Title">地区3</Field>
<Field Name="RegionName">USA</Field>
</Row>
</Rows>
</Data>
if (myfieldtype == 7 & myfieldhidden !== true & myreadonly !== true) {
var html;
//var lookupname = listItem.get_fieldValues()[internalName].get_lookupValue();//获得人员名
html = title + "</br><select id= " + internalName + "/></select></br>";
$("#test1").append(html);
var mylookuplistId = oField.get_lookupList();
//getLookupChoices
//从mylookuplist获取所有的项的Title, 然后id=internalName的select里添加option
//
getLookupChoices(internalName,mylookuplistId);
}
根据FieldKindType找出7为Lookup
function getLookupChoices(internalName, mylookuplistId) {
var list = web.get_lists().getById(mylookuplistId);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>3</RowLimit></View>');
var listItems = list.getItems(camlQuery);
context.load(listItems);
context.executeQueryAsync(Function.createDelegate(this, onSucceeded), Function.createDelegate(this, onFailed));
function onSucceeded() {
var listItemEnumerator = listItems.getEnumerator();
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
var lookupName = listItem.get_fieldValues()["RegionName"];
var lookupOption = '<option value=' + lookupName + '> ' + lookupName + '</option>';
$('#' + internalName + '').append(lookupOption);
}
}
function onFailed() {
}
}