0
目标:我希望$ scope.pluraliser在选择一年时返回随机值。 1966 目前如果多个值相同,它总是会选择最后一个值。使用Fisher耶茨随机阵列算法AngularJS如何从ng-pluralizer中获得随机值?
$ scope.pluralizer = {
1966 : "Something New !",
1966 : "Something Different!",
1966 : "Something Else",
1967 : "Something New !",
1967 : "Something Different!"',
1967 : "Something Else",
1968 : "Something New !",
1968 : "Something Different!",
1968 : "Something Else"
}
You can randomise nested lists quite easily with ng-repeat
http://jsfiddle.net/owenmead/fa4v8/1/
$ scope.list = [
'"1966" : "Something New !"',
'"1966" : "Something Different!"',
'"1966" : "Something Else"',
'"1967" : "Something New !"',
'"1967" : "Something Different!"',
'"1967" : "Something Else"',
'"1968" : "Something New !"',
'"1969" : "Something Different!"',
'"1970" : "Something Else"',
]
$scope.random = function() {
return 0.5 - Math.random();
HTML
<p ng-repeat="i in list|orderBy:random">{{i}}</p>
和随机化阵列如何可以随机化Pluralizer所以它会在选择一年后返回不同的/随机值?