我正在制作一个简单的网页, 它只是在页面加载时显示一个随机引号。AngularJS如何在ng-repeat中重新洗牌数据?
我带来了JSON数据,并用以下
app.filter('shuffle', function() {
var shuffledArr = [],
shuffledLength = 0;
return function(arr) {
var o = arr.slice(0, arr.length);
if (shuffledLength == arr.length) return shuffledArr;
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
shuffledArr = o;
shuffledLength = o.length;
return o;
};
过滤器,我使用这个过滤器像
<section id="bg" ng-controller="QuoteCtrl">
<div class="wrap_quote" ng-repeat="quote in quotes | shuffle | limitTo:1">
<pre class="quote">{{ quote.gsx$said.$t }}</pre>
<p class="from">{{ quote.gsx$from.$t }}</p>
</div>
</section>
的问题是,我怎么能不加载刷新页面新的随机数据? 我试过了。
$scope.loadData = function() {
http.get("https://spreadsheets.google.com/feeds/list/1e3oNuL79PBq-xSvpovbppM5j4aUzgzHfkl5c6x1HzAc/od6/public/values?alt=json")
.success(function(response) {
$scope.quotes = response.feed.entry;
});
}
$scope.loadData();
和HTML
<button ng-click="loadData()">RELOAD</button>
,但什么都没有发生...... 请帮帮我!
http://plnkr.co/edit/RYcGMf?p=preview
检查我的回答 –
马克我的回答是,如果你想 –