简体   繁体   English

Typescript Dynamics CRM window.parent

[英]Typescript Dynamics CRM window.parent

Since I am using webresource in my CRM functionality I need to use 由于我在我的CRM功能中使用webresource,我需要使用

window.parent.Xrm.Page...etc 

to access entity data. 访问实体数据。

Unfortunately, as I write in typescript, this construction won't compile. 不幸的是,正如我在typescript中编写的那样,这种结构不会编译。 For now I just add window.parent before Xrm.Page ...(I got Xrm typings) by hand but this is very far from TypeScript idea. 现在我只是在Xrm.Page之前添加window.parent ...(我得到了Xrm打字)但这离TypeScript的想法很远。 Is there any way, some typings or so, that would let me call window.parent.Xrm in a normal, elegant way? 是否有任何方式,一些类型,让我以正常,优雅的方式调用window.parent.Xrm? I am using Visual Studio 我正在使用Visual Studio

I guess there is no way how to get around grabbing root reference via window.Xrm object, however you can encapsulate it so it happen just once. 我想如何通过window.Xrm对象无法绕过抓取根引用,但是你可以封装它,所以它只发生一次。

If you're using correct ts templates - ie: 如果你使用正确的ts模板 - 即:

Install-Package xrm.TypeScript.DefinitelyTyped

It should be simple as 它应该很简单

class Bar {
    constructor(private xrm: Xrm.XrmStatic) {}
    foo() {
        //work in strongly typed world
        //return this.xrm.Page....;
    }
}

And than just once initialize it like 而不仅仅是一次初始化它

var bar = new Bar(window.Xrm);  
bar.foo();

I use (<any>window.parent).Xrm. 我使用(<any>window.parent).Xrm. in to get an error free compile with window.parent.Xrm . 中使用window.parent.Xrm获得无错编译。 For example: 例如:

let nameAttr = (<any>window.parent).Xrm.Page.data.entity.attributes.get("name").getValue()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM