gpt4 book ai didi

javascript - AngularJS:将表单字段的值设置为各种对象属性

转载 作者:行者123 更新时间:2023-12-03 04:30:18 25 4
gpt4 key购买 nike

我有一个简单的 AngularJS 动态表单,它由 ng-model 绑定(bind)到属性 modelParams.value。每个表单字段都显示 modelParams.value 的值但是,我想要一个名为“Default”的按钮,它将所有表单字段的值设置为此关联数组中的某些其他属性,例如 modelParams.defaultValue 或 modelParams。旧值。我假设一旦按下“默认”按钮,这将覆盖 ng-model="modelParams.value"的值。

表格如下:

<form name="modelParamsForm">                   
<div class="form-group" ng-repeat="modelParam in modelParams">
<div class="row">
//INPUT FORM FIELDS
<input type="number" class="form-control input-sm" required ng-
model="modelParam.value" >
</div>
</div>

<button class="btn btn-primary btn-sm" ng-
click="updateModelParams(modelParams, modelParamsForm)">
</button>
//DEFAULT BUTTON
<button type="button" class="btn btn-default btn-sm" ng-
click="default()">Default</button>
</form>

我的 JSON 如下所示:

[{"model":"MAF","paramname":"CascDefaultSpreadOverride","minvalue":"0","maxvalue":"100","description":"The defaault repo spread override to use for CASC positions.","defaultvalue":1.0,"value":1.0,"datatype":"FLOAT"},{"model":"MAF","paramname":"DefaultLotSize","minvalue":"1","maxvalue":"1000","description":"The minimum lot size that must be met for a collateral allocation.","defaultvalue":1.0,"value":1.0,"datatype":"INTEGER"},{"model":"MAF","paramname":"HtbColdHaircut","minvalue":"0","maxvalue":"100","description":"The haircut to apply to positions with a Cold HTB category.","defaultvalue":0.1,"value":0.1,"datatype":"FLOAT"},{"model":"MAF","paramname":"HtbExtraHotHaircut","minvalue":"0","maxvalue":"100","description":"The haircut to apply to positions with a Extra-Hot HTB category.","defaultvalue":0.9,"value":0.9,"datatype":"FLOAT"},]

最佳答案

$scope.field = 'value';

$scope.change = function() {
$scope.field = 'oldValue';
}


...ng repeat blabla
<input ng-model="modelParam[field]"/>
...
<button ng-click="change()">Change</button>

编辑:这是一个工作演示:http://jsfiddle.net/zy94an54/

关于javascript - AngularJS:将表单字段的值设置为各种对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43521871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com