0
이름의 데이터 목록이 있습니다. 이름을 선택할 때 전화 번호와 위치 필드를 자동 채우기를 원합니다. < TD> 열을 클릭하여 각 컨트롤러에 범위의 값이 내 코드입니다 :dataList 옵션을 선택할 때 다른 필드 자동 채우기 - AngularJs
HTML 소스 :
<div ng-controller="facture_retour"">
<table>
<thead>
<tr>
<td><strong>Client</strong></td>
<td>
<input type="text" id="client_List" list="clientList" />
<datalist id="clientList">
<option ng-repeat="fc in facture_client_retour" data-tele="{{fc.phone_number}}" data-location="{{fc.location}}" data-id="{{fc.id}}" value="{{fc.fname}} {{fc.lname}} |{{fc.code}}" id="optIdFc">
</datalist>
</td>
</tr>
<tr>
<td ng-click="getClientAttr();"><strong>Telephone</strong></td>
<td>{{clientPhoneNumber}}</td>
</tr>
<tr>
<td><strong>Location</strong></td>
<td>{{clientLocation}}</td>
</tr>
</thead>
</table>
</div>
내가 오류를 받고하지 오전이 때 잘 작동를 클릭하십시오.td> getClientAttr() 함수를 호출 할 수 있지만 옵션을 선택하면 자동으로이 함수를 호출해야합니다. JS의 SOURCE :
app.controller('facture_retour',function($scope, $http){
$scope.facture_client_retour;
angular.element(document).ready(function() {
$scope.getAllClients();
});
/*This function is responsible of getting all clients Name and display them
in the data-list */
$scope.getAllClients=function(){
var url = '../php/mainPageFacture.php';
var data = {"function":"getAllClients"};
var options={
type : "get",
url : url,
data: data,
dataType: 'json',
async : false,
cache : false,
success : function(response,status) {
$scope.facture_client_retour = response;
$scope.$apply();
},
error:function(request,response,error){
// alert("Error: " + error + ". Please contact developer");
swal({
title: "Please contact your software developer",
text: "ERROR: " + error,
type: "warning",
showCancelButton: false,
confirmButtonClass: "btn-info",
confirmButtonText: "Ok",
closeOnConfirm: true
});
}
};
$.ajax(options);
$scope.call=getClientAttr();
}
/*this function getting the other fields (phone number,location) values and
display them by clicking on <td>*/
$scope.getClientAttr=function(){
//alert("here we go");
var val = $('#client_List').val()
var client_phone_number= $('#clientList option').filter(function() {
return this.value == val;
}).data('tele');
$scope.clientPhoneNumber=client_phone_number;
var val = $('#client_List').val()
var client_location= $('#clientList option').filter(function() {
return this.value == val;
}).data('location');
$scope.clientLocation=client_location;
}
});
좋은 생각 인 것 같습니다. 그러나 왜 이것이 전혀 작동하지 않는지, 어떤 편집을했는지 모르겠습니다. o.O –
콘솔에 오류가 있습니까? – NTP
콘솔에 오류가 기록되지 않았습니다! –