javascript - 如何使用选择选项作为该函数的参数来调用更改选择选项的函数
问题描述
我想在选择值随角度参数变化时调用函数
<div class="col-sm-6 col-md-4">
<label class="mobileNumberLabel " for="mobilrNumber">Select Service</label>
<div class="nice-wrap">
<select (change)="checkCategory(item.price,item.serviceName,m,k,'add');" class="js-example-basic-single nice-textbox" >
<optgroup *ngFor="let item of serviceObject;let k = index" label='{{item.categoryName}}'>
<option *ngFor="let service of item.services;let m = index">
{{service.serviceName}} - {{item.categoryName}}
</option>
</optgroup>
</select>
</div>
</div>
我希望那些选择的选项价格和服务名称作为 checkCategory 函数的参数。有什么办法可以做到这一点。?
解决方案
您可能无法传递代码中编写的这些值,因为item, m, k
它们不在范围内。相反,您可以传递$event
给处理函数并使用它event.target.selectedOptions[0].parentElement
来访问选定的 optGroup 元素。
推荐阅读
- java - 没有找到类“android.support.v4.app.CoreComponentFactory”
- javascript - 在 JavaScript 中将已兑现的文件重新加载到浏览器 serviceWorker
- javascript - 如何修改 codemirror 的自动完成功能
- c++ - C++ 命名空间警告 - 声明隐藏全局声明 VS 2015 警告 C4459
- project-reactor - 线程在反应器执行中是否曾经更改过一次?
- string - Haskell 最后一个字符串
- java - 如何在不同的方法中使用arraylist,但方法在类内部
- php - PHP preg_match 检查文件名以括号数字结尾(例如文件名(1).pdf)
- regex - Using re.finditer to generate iterative object, but no return, the regex code is ok when testing separately
- syntax-error - 寻求帮助以纠正我的 Verilog 代码中的语法错误