使用 verbose 选项获取 optionset 和 lookup 值

默认情况下,你将获得选项集和查找的 de 代码和 ID。如果你还想获得标签,则需要为调用添加额外的标头。

$.ajax({
    url: Xrm.Page.context.getClientUrl() + '/api/data/v8.0/contacts',
    headers: { 
        'Accept': 'Application/json', 
        'Prefer': 'odata.include-annotations="OData.Community.Display.V1.FormattedValue"' 
    }
}).done(function (result) {
    $.each(result.value, function (key, value) {
        //sample to access a label
        var gendercodeLabel = value['gendercode@OData.Community.Display.V1.FormattedValue'];
        var gendercodeValue = value.gendercode;
    });
});