单击按钮时无法使用 ng-repeat 将值绑定到 select 的 ng-model
unable to bind value to ng-model of select with ng-repeat on button click
我有如下的 TableObject
$scope.tableObject = [
{
'Column_Name' : 'Dummy 1',
'Column_Cliass' : 'Valid'
},
{
'Column_Name' : 'Dummy 2',
'Column_Cliass' : 'Invalid'
}
]
现在使用 ng-repeat 绘制 select 控件,如下所示。
<div class="row networkDataBR" ng-repeat="lTable in tableObject">
<select class="form-control" ng-model="lookupFile" ng-options="option as option.name for option in onlyFiles">
</select>
</div>
它将生成两个 Select 控件,现在单击按钮我想将值分配给控制器中的一个 select 控件。
<input class="btn btn-primary" type="button" ng-click="appendFile("Network")" value="Append" />
$scope.appendFile = function(dataValue) {
_.each($scope.tableObject, function (lTable) {
if (lTable.Column_Name === "dummy") {
$scope.lookupFile = dataValue;
}
});
};
但是,它同时适用于select控件。那么如何申请单身select?
您对两个 select 控件使用相同的模型变量。使用像这样的不同变量
<div class="row networkDataBR" ng-repeat="lTable in tableObject">
<select class="form-control" ng-model="lookupFile[$index]" ng-options="option as option.name for option in onlyFiles">
</select>
</div>
<input class="btn btn-primary" type="button" ng-click="appendFile("Network",0)" value="Append" />
$scope.lookupFile={};
$scope.appendFile = function(dataValue,index) {
_.each($scope.tableObject, function (lTable) {
if (lTable.Column_Name === "dummy") {
$scope.lookupFile[index] = dataValue;
}
});
};
我有如下的 TableObject
$scope.tableObject = [
{
'Column_Name' : 'Dummy 1',
'Column_Cliass' : 'Valid'
},
{
'Column_Name' : 'Dummy 2',
'Column_Cliass' : 'Invalid'
}
]
现在使用 ng-repeat 绘制 select 控件,如下所示。
<div class="row networkDataBR" ng-repeat="lTable in tableObject">
<select class="form-control" ng-model="lookupFile" ng-options="option as option.name for option in onlyFiles">
</select>
</div>
它将生成两个 Select 控件,现在单击按钮我想将值分配给控制器中的一个 select 控件。
<input class="btn btn-primary" type="button" ng-click="appendFile("Network")" value="Append" />
$scope.appendFile = function(dataValue) {
_.each($scope.tableObject, function (lTable) {
if (lTable.Column_Name === "dummy") {
$scope.lookupFile = dataValue;
}
});
};
但是,它同时适用于select控件。那么如何申请单身select?
您对两个 select 控件使用相同的模型变量。使用像这样的不同变量
<div class="row networkDataBR" ng-repeat="lTable in tableObject">
<select class="form-control" ng-model="lookupFile[$index]" ng-options="option as option.name for option in onlyFiles">
</select>
</div>
<input class="btn btn-primary" type="button" ng-click="appendFile("Network",0)" value="Append" />
$scope.lookupFile={};
$scope.appendFile = function(dataValue,index) {
_.each($scope.tableObject, function (lTable) {
if (lTable.Column_Name === "dummy") {
$scope.lookupFile[index] = dataValue;
}
});
};