由于我是打字稿的新手,我想扩展一段时间前发布的关于打字稿中的通配符的问题。 Here is the original question.
My Angular 2 / Web.API / MVC应用程序在我的数据库中使用递归搜索来返回填充过滤器模态的不同类型列表,分为3个不同的列。当用户在其中一个选择列表上选择一个值时, 我想填充其他2个选择列表,其中包含与第一个选择列表匹配的所有可用值。但目前,' UNDEFINED'从组件传递到控制器,导致它查找空值,而不是所有值。
所以这是我的组件的强制性代码:
我的更新活动:
UpdateAllLookups(event) {
this.allLookups = [];
if ("year" == event.srcElement.id) {
this.corrCodesfilter.rgln_Year = this.getSelectedItem("year").value
} else { this.corrCodesfilter.rgln_Year = this.corrCodesfilter.rgln_Year; }
if ("regType" == event.srcElement.id) {
this.corrCodesfilter.rgln_type_code = this.getSelectedItem("regType").value;
} else { this.corrCodesfilter.rgln_type_code = this.corrCodesfilter.rgln_type_code;}
if("valdtnCode"== event.srcElement.id){
this.corrCodesfilter.valdtn_code = this.getSelectedItem("valdtnCode").value;
} else { this.corrCodesfilter.valdtn_code = this.corrCodesfilter.valdtn_code;}
this._corrCodeService.getLookupsUpdate(Global.BASE_CORRECTION_CODE_ENDPOINT + "GetLookupsUpdate?", this.corrCodesfilter)
.subscribe(allLookups => {
this.allLookups = allLookups;
this.getYearLookups();
this.getRegLookups();
this.indLoading = false;
}, error => this.msg = <any>error);
}
如果我在c#工作,我会通过:
if(String.IsNullOrEmpty(this.corrCodesFilter.rgln_Year)){
this.corrCodesFilter.rgln_Year = *;}
如果值未定义,是否可以执行任何通配符传递?我没能用未定义的值命中我的控制器,或者我会在那里完成它。非常感谢任何帮助。
答案 0 :(得分:2)
如果字段未定义,您可以执行以下操作来指定默认值:
this.corrCodesFilter.rgln_Year = this.corrCodesFilter.rgln_Year || '*';
如果this.corrCodesFilter.rgln_Year
不是undefined
,则上面的表达式将返回'*'
,如果this.corrCodesFilter.rgln_Year
是undefined
,则会返回onFocusIn
。