Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating loaded models with JS
    primarykey
    data
    text
    <p>To explain my exact use-case: So I have a news-model with a 'created_at' field. Displaying all the dates with an ArrayController works fine and as expected. But what I want to do now, is converting these dates into fuzzy times with <a href="http://pragmaticly.github.io/smart-time-ago/" rel="nofollow">http://pragmaticly.github.io/smart-time-ago/</a> (or <a href="http://timeago.yarp.com/" rel="nofollow">http://timeago.yarp.com/</a>). The problem here is, I need to call <code>$('.timeago').timeago('refresh');</code> once the timestamps are loaded and displayed. That seems to work fine as long as I navigate within the ember-app. But when I refresh a site the plugin somehow can't convert it. So I suppose the command doesn't get called at the right time from the app. I am doing that in the following two ways right now: in the View:</p> <pre><code>didInsertElement: function(){ $('body').timeago('refresh'); } </code></pre> <p>and in the Controller:</p> <pre><code>updateFuzzyTime: function(){ $('body').timeago('refresh'); }.observes('content') </code></pre> <p>When I do it in either place with the <code>setTimeout()</code> command set to 1000ms it obviously does work.</p> <p>So how can I get ember to perform that command when a model is fully loaded and displayed on a refresh? (In another project I had a similar issue and there I used the <code>rerender()</code> command which did work, but in this use-case I simply can not do that)</p> <p>Edit: Just to post it here as well. The plugin looks at the datetime-attribute of a time element. So my hbs code looks like this:</p> <pre><code>&lt;time class="timeago" {{bindAttr datetime="date"}}&gt;{{date}}&lt;/time&gt; </code></pre> <p>And I suppose the reason why most hooks don't work is because even though the DOM is rendered I suppose Ember hasn't updated the attribute yet.</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.
 

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