Angular.js新手。我有一个函数可以获取数据并将它们放入对象中:
$scope.ContractComboBoxOptions = function (entyId, fieldId, value, contractIndex, searchOptionsName) {
entityService.searchComboBoxItems(entyId, fieldId, value)
//result below needs to have an array with results
.then(function (result) {
var endItems = [];
var icountr = 0;
var test = result.updatedAddContract[0];
angular.forEach(result, function (attr) {
test = result.updatedAddContract[icountr];
endItems.push(test);
icountr++;
});
//$scope[searchOptionsName] = endItems;
$scope.contracts[contractIndex][searchOptionsName] = endItems;
});
};
如果我将鼠标移到endItems上,你可以看到它们:
我试图在挑选一列时设置2列。当我选择第一列时,数据正常:
但它不会像我想要的那样填充下一个字段。
<tbody data-ng-repeat="(contractIndex, contract) in contracts">
<tr>
<td>
<div class="dropdown" style="width:100%">
<input type="text" class="form-control input-sm dropdown-toggle" data-toggle="dropdown" data-ng-disabled="formReadOnly" data-ng-model="contract.CONTRACT_NUM_VAL" data-ng-keyup="ContractComboBoxOptions(14, 413, contract.CONTRACT_NUM_VAL, contractIndex, 'searchContractOptions')" />
<ul class="dropdown-menu small" style="width:100%">
<li data-ng-repeat="name in contract.searchContractOptions" style="width:100%"><a data-ng-click="changeContractData(contractIndex, 'CONTRACT_NUM_VAL', name.name)">{{name.name}}</a></li>
</ul>
</div>
</td>
<td><input type="number" class="form-control input-sm" data-ng-model="contract.ITEM_ID" />{{name.ITEM_ID}}</td>
</tbody>
当选择第一个时,如何让另一个字段填充进入的对象?
编辑:结果json:
[{"ITEM_ID":2,"name":"10/29/2016","PROGRAM_ID":"4"},{"ITEM_ID":2,"name":"10/31/2016","PROGRAM_ID":"4"},{"ITEM_ID":2,"name":"111111111","PROGRAM_ID":"4"},{"ITEM_ID":2,"name":"A180","PROGRAM_ID":"4"},{"ITEM_ID":3,"name":"01/29/2017","PROGRAM_ID":"1"},{"ITEM_ID":3,"name":"01/31/2017","PROGRAM_ID":"1"},{"ITEM_ID":3,"name":"1","PROGRAM_ID":"1"},{"ITEM_ID":6,"name":"02/01/2017","PROGRAM_ID":"3"},{"ITEM_ID":6,"name":"02/22/2017","PROGRAM_ID":"3"},{"ITEM_ID":6,"name":"123456","PROGRAM_ID":"3"},{"ITEM_ID":6,"name":"M150","PROGRAM_ID":"3"},{"ITEM_ID":7,"name":"02/27/2017","PROGRAM_ID":"4"},{"ITEM_ID":7,"name":"02/28/2017","PROGRAM_ID":"4"},{"ITEM_ID":7,"name":"112123123123","PROGRAM_ID":"4"},{"ITEM_ID":7,"name":"A910","PROGRAM_ID":"4"}]
$ Scope.contracts json:
[{"GM_FLAG":"N","COMBO_FLAG":"N","RX_MED_FLAG":"N","IV_MED_FLAG":"N","INCENTIVE_FLAG":"N","NDC_ID":-1,"searchContractOptions":[{"ITEM_ID":2,"name":"10/29/2016","PROGRAM_ID":"4"},{"ITEM_ID":2,"name":"10/31/2016","PROGRAM_ID":"4"},{"ITEM_ID":2,"name":"111111111","PROGRAM_ID":"4"},{"ITEM_ID":2,"name":"A180","PROGRAM_ID":"4"},{"ITEM_ID":3,"name":"01/29/2017","PROGRAM_ID":"1"},{"ITEM_ID":3,"name":"01/31/2017","PROGRAM_ID":"1"},{"ITEM_ID":3,"name":"1","PROGRAM_ID":"1"},{"ITEM_ID":6,"name":"02/01/2017","PROGRAM_ID":"3"},{"ITEM_ID":6,"name":"02/22/2017","PROGRAM_ID":"3"},{"ITEM_ID":6,"name":"123456","PROGRAM_ID":"3"},{"ITEM_ID":6,"name":"M150","PROGRAM_ID":"3"},{"ITEM_ID":7,"name":"02/27/2017","PROGRAM_ID":"4"},{"ITEM_ID":7,"name":"02/28/2017","PROGRAM_ID":"4"},{"ITEM_ID":7,"name":"112123123123","PROGRAM_ID":"4"},{"ITEM_ID":7,"name":"A910","PROGRAM_ID":"4"}],"$$hashKey":"00O","CONTRACT_NUM_VAL":"1"}]