如何在typescript中动态地向对象添加属性?这是一个示例方法:
processSearchResults(responseObject)
{
var blogPostSearchResults = Object.assign(new GetBlogPostsResponse(), responseObject);
this.blogPostSearchResults = blogPostSearchResults.CollectionResults;
var authorList = ['John Smith', 'Bill Jones'];
//append author list to each result
for (var blogPost in this.blogPostSearchResults)
{
blogPost.AuthorList = authorList ;
}
}
在上面的示例中,我采用具有特定定义的对象,然后尝试动态创建和分配新属性,以便为html模板视图绑定提供额外的结构。