在使用for循环时,let对象具有字符串类型,即使我迭代的对象是在接口中定义的类型.
以下是我正在使用的代码.当尝试访问在接口上定义的mapping.attribute作为字符串时,我得到错误[属性'属性'在类型'字符串'上不存在.
我有以下界面和功能:
interface IMapping {
attribute: string;
property: string;
}
mapAttributes(mappings: IMapping[], values) {
for (let mapping in mappings) {
if (mapping.hasOwnProperty("attribute")) {
console.log(this.attributes.find(attribute => attribute.name === mapping.attribute).value);
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何定义for循环以便我可以使用在我的界面中定义的属性?
我有以下代码,基本上它接受一个动态对象(在这种情况下是类型文件)并使用HTTPClient类尝试POST到a WebAPI controller,我遇到的问题是控制器总是获取NULL我的[FromBody]参数上的值.
var obj = new
{
f = new File
{
Description = description,
File64 = Convert.ToBase64String(fileContent),
FileName = fileName,
VersionName = versionName,
MimeType = mimeType
},
}
var client = new HttpClient(signingHandler)
{
BaseAddress = new Uri(baseURL + path) //In this case v1/document/checkin/12345
};
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response;
action = Uri.EscapeUriString(action);
//Obj is passed into this, currently it is of type File
var content = new StringContent(JsonConvert.SerializeObject(obj).ToString(),
Encoding.UTF8, …Run Code Online (Sandbox Code Playgroud)