Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在按钮按下/事件触发器上传递选定的对象模型_Javascript_Angularjs_Html - Fatal编程技术网

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)">&nbsp;&lt;&#61;&nbsp;</button>