【问题标题】:How to set more than one Angular2 var in Jquery onchange如何在 Jquery onchange 中设置多个 Angular2 var
【发布时间】:2017-10-27 04:33:54
【问题描述】:

我无法在 Angular2 的 jquery 中分配多个 var。

我正在做的是:

jQuery('.source-select').on('change',(e) => this.updateForm.value.sources = jQuery(e.target).val().split('--')[0]);

这工作正常,但我想将索引 [1] 的拆分值分配给另一个对象:

  jQuery('.source-select').on('change',(e) => this.updateForm.value.sources = jQuery(e.target).val().split('--')[0]
   ,(e) => this.selected_text = jQuery(e.target).val().split('--')[1]
   );

但此时我设置了 this.selected_text 而不是 this.updateForm.value.sources 。猜猜我做错了什么。

*** 我尝试使用 on change 两次,效果很好,但我认为这样做不好。

【问题讨论】:

    标签: javascript jquery typescript angular2-forms


    【解决方案1】:

    我不知道我是否真的理解你的问题,但你为什么不像这样使用它呢?

     jQuery('.source-select').on('change',function(e){
        this.updateForm.value.sources = jQuery(e.target).val().split('--')[0];       
        this.selected_text = jQuery(e.target).val().split('--')[1];        
    });
    

    【讨论】:

    • 我已经尝试过了,但我认为无法读取 updateForm.value 处未定义的属性“值”。
    • 当您将 this 与事件一起使用时, this === e.currentTarget 将返回 true,如果 currentTarget 和 target 相同,则 this === e.target 将返回 true。也许你没有使用你认为“this”的值。
    猜你喜欢
    • 2018-02-10
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 2017-11-16
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多