获取 Microsoft Graph ToolkitGet component in the Microsoft Graph Toolkit

可以使用 直接 mgt-get 在 HTML 中从 Microsoft Graph 进行任何 GET 查询。You can use mgt-get to make any GET query from Microsoft Graph directly in your HTML. 该组件不提供默认 UI,并且要求你编写模板。The component does not provide a default UI and requires that you write a template.

示例Example

下面的示例展示了如何使用 组件 mgt-get 显示用户的电子邮件。The following example shows the use of the mgt-get component to display a user's emails. 可以使用代码编辑器查看属性 和属性 如何更改组件的行为。You can use the code editor to see how properties and attributes change the behavior of the component.

在"打开"mgt.devOpen this example in mgt.dev

属性和属性Properties and attributes

可以使用多个属性更改组件的行为。You can use several attributes to change the behavior of the component. 唯一必需的属性是 resourceThe only required attribute is resource.

属性Attribute 属性Property 说明Description
资源resource resourceresource 从 Microsoft Graph 获取的资源 (例如 /me ,) 。The resource to get from Microsoft Graph (for example, /me).
scopesscopes scopesscopes 字符串的可选数组(如果使用 属性)或逗号分隔的范围(如果使用 属性)。Optional array of strings if using the property or a comma delimited scope if using the attribute. 组件将使用这些作用域 (支持) ,以确保用户已同意适当的权限。The component will use these scopes (with a supported provider) to ensure that the user has consented to the right permission.
versionversion versionversion 进行 GET 请求时使用的可选 API 版本。Optional API version to use when making the GET request. 默认值为“v1.0”。Default is v1.0.
max-pagesmax-pages maxPagesmaxPages 支持分页 (的资源的可选页面) 。Optional number of pages (for resources that support paging). 默认值为 3。Default is 3. 将此值设置为 0 将获取所有页面。Setting this value to 0 will get all pages.
轮询率polling-rate pollingRatepollingRate 可选毫秒数。Optional number of milliseconds. 设置后,组件将按定义的间隔轮询请求 URI 以进行更新。When set, the component will poll the request URI for updates in the defined interval. 如果使用增量查询,轮询将始终查询 delta API。If using a delta query, polling will always query the delta API. 模板仅在数据更改时刷新。The template will only refresh when the data changes.
启用缓存cache-enabled cacheEnabledcacheEnabled 可选属性,类型为 Boolean。Optional Boolean. 设置后,它指示将缓存来自资源的响应。When set, it indicates that the response from the resource will be cached. Overriden if refresh() is called or if is in pollingRate use.Overriden if refresh() is called or if pollingRate is in use. 默认值为“false”。Default is false.
cache-invalidation-periodcache-invalidation-period cacheInvalidationPeriodcacheInvalidationPeriod 可选毫秒数。Optional number of milliseconds. 如果与 一起设置 ,则此值将修改缓存达到其无效时段 cacheEnabled 前的延迟。When set in combination with cacheEnabled, the delay before the cache reaches its invalidation period will be modified by this value. 默认值为 0 ,将使用默认无效时段。Default is 0 and will use the default invalidation period.
typetype typetype 预期响应的可选类型。Optional type of the expected response. 默认值为“json”。Default is json. 仅在 (终结点上支持或 json image 支持 /photo/value$) 。Supports json or image (only be supported on endpoints ending with /photo/value$).
不适用N/A 响应response 如果请求成功,来自 Microsoft Graph 的只读响应。Read-only response from Microsoft Graph if request was successful.
不适用N/A errorerror 如果请求未成功,Microsoft Graph 中出现只读错误。Read-only error from Microsoft Graph if request was not successful.

方法Methods

方法Method 说明Description
refresh (force?:boolean) refresh(force?:boolean) 调用 方法以刷新数据。Call the method to refresh the data. 默认情况下,UI 仅在数据发生更改时更新。By default, the UI will only update if the data changes. 传递 true 以强制组件更新。Pass true to force the component to update.

事件Events

事件Event 详情Detail 说明Description
dataChangedataChange 详细信息包含 responseerror 对象。The detail contains the response and error objects. 响应或错误更改时触发。Fired when the response or error change.

模板Templates

mgt-get组件支持多个可用于定义外观的模板。The mgt-get component supports several templates that you can use to define the look and feel. 若要指定模板,请包含组件 <template> 中的元素,将值 data-type 设置为以下值之一。To specify a template, include a <template> element inside a component and set the data-type value to one of the following.

数据类型Data type 数据上下文Data context 说明Description
defaultdefault 来自 Microsoft Graph 的响应。The response from Microsoft Graph. 需要默认模板才能呈现来自 Microsoft Graph 的数据。The default template is required to render the data coming from Microsoft Graph.
value 返回的数组的数据 valueData item from the returned value array 当预期来自图形的响应包含项目数组(如消息、文件或用户)时,请使用模板而不是 value default 模板Use the value template instead of the default template when expecting the response from the graph to contain an array of items - such as messages, files, or users. 将自动 value 为资源返回的每个项目重复模板。The value template will automatically be repeated for each item returned by the resource. 模板还会在准备好项目后立即开始呈现 (value 默认模板) 。The value template will also start rendering the items as soon as they are ready (unlike the default template).
errorerror Microsoft Graph 中的错误。The error from Microsoft Graph. 如果提出请求出错,将使用此模板。This template will be used if there is an error making the request.
loadingloading 不适用N/A 请求时使用此模板。This template is used while the request is being made.

Microsoft Graph 权限Microsoft Graph permissions

有关权限详细信息,请参阅 Microsoft Graph 权限参考For more information about permissions, see the Microsoft Graph permissions reference.

身份验证Authentication

该控件使用身份验证文档中介绍的全局身份验证提供程序获取所需数据。The control uses the global authentication provider described in the authentication documentation to fetch the required data.

缓存Cache

若要启用和配置缓存,请使用 cacheEnabledcacheInvalidationPeriod 属性。To enable and configure the cache, use the cacheEnabled and cacheInvalidationPeriod properties. 默认情况下, mgt-get 该组件不缓存任何响应。By default, the mgt-get component does not cache any responses.

对象存储Object store 缓存数据Cached data 备注Remarks
response 从 Microsoft Graph 检索到的完整响应,该响应针对 的 resource 属性中指定的查询 mgt-getComplete response retrieved from Microsoft Graph for the query specified in the resource property of mgt-get

有关详细信息 请参阅缓存。See Caching for more details.