我试图在TypeScript中编写一个类,该类具有一个定义的方法,该方法充当jQuery事件的事件处理程序回调.
class Editor {
textarea: JQuery;
constructor(public id: string) {
this.textarea = $(id);
this.textarea.focusin(onFocusIn);
}
onFocusIn(e: JQueryEventObject) {
var height = this.textarea.css('height'); // <-- This is not good.
}
}
Run Code Online (Sandbox Code Playgroud)
在onFocusIn事件处理程序中,TypeScript将"this"视为该类的"this".但是,jQuery会覆盖此引用并将其设置为与事件关联的DOM对象.
另一种方法是在构造函数中将lambda定义为事件处理程序,在这种情况下,TypeScript会创建一种带有隐藏_this别名的闭包.
class Editor {
textarea: JQuery;
constructor(public id: string) {
this.textarea = $(id);
this.textarea.focusin((e) => {
var height = this.textarea.css('height'); // <-- This is good.
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,是否有另一种方法来使用TypeScript在基于方法的事件处理程序中访问此引用,以克服此jQuery行为?
如果POST主体的长度大于8192个字符,则WCF 4.0 REST项目将返回400 Bad Request错误.这是XmlDictionaryReaderQuotas.MaxStringContentLength属性的默认值.XmlDictionaryReader类用于反序列化过程,即使对于JSON消息也是如此.
我已经看到很多关于如何使用自定义绑定和端点为WCF解决此问题的示例,但没有使用简化配置的WCF 4.0 REST项目的解决方案.
普通的web.config文件包含一个如下所示的部分:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
首先,需要增加消息大小.为此,请将maxReceivedMessageSize添加到standardEndpoint.
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="65535" />
Run Code Online (Sandbox Code Playgroud)
要设置MaxStringContentLength,请将以下内容添加到system.serviceModel部分:
<bindings>
<webHttpBinding>
<binding>
<readerQuotas maxStringContentLength="65535"/>
</binding>
</webHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
您需要将长度设置为适合您环境的值.