Javascript 在按钮按下/事件触发器上传递选定的对象模型
我有一个按钮,当前将所选值传递给Javascript 在按钮按下/事件触发器上传递选定的对象模型,javascript,angularjs,html,Javascript,Angularjs,Html,我有一个按钮,当前将所选值传递给removeContract() 根据当前代码的一些建议: 与其将整个{{contract.CONT_ORDNO}}-{contract.SUPP_NAME}[{{contract.SUPP_NUM}}]传递到ng模型中,只需传递contract.CONT_ORDNO以从下拉列表中标识所选数据 <option data-ng-repeat="contract in contracts" value="contract.CONT_ORDNO">{{c
removeContract()
根据当前代码的一些建议:
- 与其将整个
{{contract.CONT_ORDNO}}-{contract.SUPP_NAME}[{{contract.SUPP_NUM}}]
传递到ng模型中,只需传递contract.CONT_ORDNO
以从下拉列表中标识所选数据
<option data-ng-repeat="contract in contracts" value="contract.CONT_ORDNO">{{contract.CONT_ORDNO}} - {{contract.SUPP_NAME}}[{{contract.SUPP_NUM}}]</option>
- 根据所选值,我们可以借助数组方法从
contracts
函数中的contract
数组中删除contract
对象
演示
var myApp=angular.module('myApp',[]);
myApp.controller('MyCtrl',函数($scope){
$scope.contracts=[
{
“CONT_ORDNO”:“1”,
“供应商名称”:“阿尔法”,
“供应数量”:“0001”
},
{
“CONT_ORDNO”:“2”,
“供应商名称”:“beta”,
“供应数量”:“0002”
},
{
“CONT_ORDNO”:“3”,
“供应商名称”:“gaama”,
“供应数量”:“0003”
},
{
“CONT_ORDNO”:“4”,
“供应商名称”:“xyz”,
“供应数量”:“0004”
}
];
$scope.removeContract=函数(selectedVal){
var removedObj=$scope.contracts.filter(函数(项){
return item.CONT_ORDNO!=selectedVal;
});
console.log(removedObj);
}
});代码>
=
{{item.fields[132].displayName}
{{contract.CONT_ORDNO}-{{contract.SUPP_NAME}[{{contract.SUPP_NUM}]
如果要通过单击选择合同,则可以添加事件侦听器onclick
将活动id添加到所选合同中contract@RandomDeveloperdata ng click使用angular在此处执行该操作。只需传递ctrl。选择Value
即可运行。你是否使用controllerAs
语法?你到底有什么问题?你的问题不清楚。。最好添加更多解释的plunker。@Rohit是的,非常有用,谢谢。
<option data-ng-repeat="contract in contracts" value="contract.CONT_ORDNO">{{contract.CONT_ORDNO}} - {{contract.SUPP_NAME}}[{{contract.SUPP_NUM}}]</option>
<button class="btn btn-primary" data-ng-click="removeContract(ctrl.selectValue)"> <= </button>