根据属性“名称”对html单选按钮排序

时间:2015-07-15 05:20:10

标签: jquery angularjs sorting radio-button

<input type="radio" name="AIM Data Quality Report" value="1" ng-click="DisplayMonthYear()" />
AIM Data Quality Report
<br />
<input type="radio" name="Compliance Report" value="14" ng-click="DisplayYear()" />Compliance Projects Report
<br />
<input type="radio" name="AIM Detailed Report" value="2" ng-click="DisplayMonthYear()" />AIM Detailed Report
<br />

输出应按此顺序为radiobuttons。

AIM数据质量报告
AIM详细报告
合规报告

1 个答案:

答案 0 :(得分:1)

一种选择是将无线电输入的值保存在控制器中的数组中,然后使用ng-repeat输出它们并按顺序对值进行排序:

<强> HTML:

<div ng-controller="MyCtrl">
    <div ng-repeat="input in radioInputs | orderBy:'name'">
        <input type="radio" name="{{input.name}}" value="{{input.value}}" ng-click="{{input.functionOnClick}}" />{{input.name}}
        <br />
    </div>
</div>

<强>的Javascript

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {

    $scope.radioInputs = [
        {id: 0, name: 'AIM Data Quality Report', value: "1", functionOnClick: "DisplayMonthYear()"},
        {id: 1, name: 'Compliance Report', value: "14", functionOnClick: "DisplayYear()"},
        {id: 2, name: 'AIM Detailed Report', value: "2", functionOnClick: "DisplayMonthYear()"}
];

}

这是一个小提琴:https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js