我正在製作一個簡單的網頁, 它只是在頁面加載時顯示一個隨機引號。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
檢查我的回答 –
馬克我的回答是,如果你想 –