0
나는 현재 직면하고 있고 여기에서 문제를 해결할 수 없다. 나는 사람들의 배열을 포함하고있는 json을 가지고 있고 각각의 사람 안에 또 다른 배열의 문자열을 가지고있다. 배열에는 숫자와 실제 문자열 값이 있습니다. 정수 자체가 문자열로 취급되므로 orderby를 사용할 때 정수가 문자열이라고 생각하기 때문에 잘못 정렬됩니다.앵귤러 JS 정렬 및 문자열을 정수로 변환
내가 알아 내려고하는 것은 ng-repeat를 사용하여 정수를 추출 할 때 문자열을 정수로 변환 할 수있는 방법입니다. 여기
내 현재 HTML입니다 :<div ng-controller="TableCtrl">
<p><strong>Page:</strong> {{tableParams.page()}}</p>
<p><strong>Count per page:</strong> {{tableParams.count()}}</p>
<table ng-table="tableParams">
<tr ng-repeat="person in $data">
<td data-title="'Name'" sortable="'0'">{{person[0]}} {{person[1]}}</td>
<td data-title="'Age'" sortable="'2'">{{ person[2] }}</td>
</tr>
</table>
</div>
현재 JSON 구조 :
0: Array[3]
0: "John"
1: "Doe"
2: "25"
내 자바 스크립트 :
angular.module("myApp").controller('TableCtrl', ['$scope', '$http', 'ngTableParams', '$filter',
function($scope, $http, ngTableParams, $filter) {
$scope.People= {};
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: 0, // length of data
getData: function($defer, params) {
$http({
method: 'GET',
url: "json.url.json"
})
.success(function(data, status, headers, config) {
$scope.tableParams.total(data.length)
$scope.People= data;
var orderedData = params.sorting() ?
$filter('orderBy')(data, params.orderBy()) :
data;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
})
.error(function(data, status, headers, config) {
// something went wrong :(
});
}
});
}
]);
가 현재 시도하고 테이블 및 정렬 기능을 실행하기 위해 http://bazalt-cms.com/ng-table/을 사용하여 . 그런 다음 그 정수를 필요로 정렬 또는 아무것도 새 필드를 사용할 수있는 등 정렬 할 수있는 필드,
angular.forEach(data,function(el,i){
el.age_int = parseInt(el.age);
});
$scope.people = data;
를 만드는 데에 온다