Note that there are some explanatory texts on larger screens.

plurals
  1. POstrange behavior of Firebase queries
    primarykey
    data
    text
    <p>I'm working on an app that stores a list of work items, which are ordered by their scheduled dates. I have 2 queries, 1 to monitor the item having the highest priority (latest schedule), and the other to monitor the one with the lowest priority (earliest schedule):</p> <pre><code> var FB = new Firebase('https://pckben-testquery.firebaseio-demo.com/'); FB.startAt().limit(1).on('child_added', function(snapshot) { var topItems = JSON.stringify(snapshot.name()); $("#topItems").text(topItems); }); FB.endAt().limit(1).on('child_added', function(snapshot) { var lastItems = JSON.stringify(snapshot.name()); $("#lastItems").text(lastItems); }); </code></pre> <p>My data is something like:</p> <pre><code>a: 1365931229230 &lt;-- scheduled date, also set as its priority b: 1365931230662 c: 1365931241984 d: 1365931258729 e: 1365931266804 </code></pre> <p>The result is not as expected: it outputs the top item, "a", for both <code>#topItems</code> and <code>#lastItems</code>. </p> <p>But if I include another query watching the entire list, then everything works as expected:</p> <pre><code> $scope.items = []; // I'm using AngularJS FB.on('value', function(snapshots) { $scope.items = []; snapshots.forEach(function(ss) { $scope.items.push({ name: ss.name(), schedule: ss.val() }); }); if (!$scope.$$phase) $scope.$apply(); }); </code></pre> <p>To understand this behavior, please first go to <a href="http://jsbin.com/azisuf/1/edit" rel="nofollow">http://jsbin.com/azisuf/1/edit</a>, and then <a href="http://jsbin.com/ejujef/1/edit" rel="nofollow">http://jsbin.com/ejujef/1/edit</a>. Clicking the update button to move the items to the last row. You will see that in the first version, the "Last Rows" section doesn't show the last rows as expected, while in the second version it does.</p> <p>The codes are tested on Chrome and Safari.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload