打字稿中的通配符

问题描述 投票:0回答:1

由于我对打字稿很新,我想扩展一段时间前发布的关于打字稿中的通配符的问题。 Here is the original question.

我的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 = *;}

如果值未定义,是否可以执行任何通配符传递?我没能用未定义的值命中我的控制器,或者我会在那里完成它。非常感谢任何帮助。

typescript wildcard angular2-forms
1个回答
2
投票

如果字段未定义,您可以执行以下操作以指定默认值:

 this.corrCodesFilter.rgln_Year = this.corrCodesFilter.rgln_Year || '*';

如果this.corrCodesFilter.rgln_Year不是undefined,那么上面的表达式将返回'*',如果this.corrCodesFilter.rgln_Yearundefined,则返回qazxswpoi。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.