The child outlet becomes empty after refreshing the URL with the ID sourced from the {{link-to}} method in Ember.js

I am facing a strange problem where the child outlet becomes empty every time I refresh the page with the id. I have a generated list using the {{link-to}} helper.

<script type="text/x-handlebars" id="twod">
        <div class="row">
            <div class="span4">
                <img src="/img/2DPipeline.jpg" />
            </div>

            <div class="span3">
                <h4>People with Roles</h4>
             <div class="row">
                 <div class="span2">    
                        <ul>
                            {{#each item in model}}
                <li>{{#link-to 'twoduser' item}}{{item.firstname}} {{/link-to}}</li>
                            {{/each}}

                        </ul>
                    </div>
                    <div class="row">
                        <div class="span">
                            {{outlet}}
                        </div>
                    </div>
                </div>
        </div>
        </script>

This is how the twoduser template looks like,

<script type="text/x-handlebars" data-template-name="twoduser">

        <div class="row">
            <div class="span3">
              Full Name: {{firstname}}{{lastname}}
              EMail: {{email}}
            </div>
        </div>

        </script>

Here is a snippet from App.js,

    App.Router.map(function() {
        this.resource('twod', function() {
            this.resource('twoduser', {
                path : ':user_id'
            });
        });
        this.resource('threed');

    });
App.TwoduserRoute = Ember.Route.extend({
    model : function(params) {
        return App.Twod.findBy(params.user_id);
    }
});

App.Twod.reopenClass({
    findAll : function() {
        return new Ember.RSVP.Promise(function(resolve, reject) {
            $.getJSON("http://pioneerdev.us/users/index", function(data) {
                var result = data.users.map(function(row) {
                    return App.Twod.create(row);
                });
                resolve(result);
            }).fail(reject);
        });
    },
    findBy : function(user_id) {
        var user = App.Twod.create();

        $.getJSON("http://ankur.local/users/byId/" + user_id, function(data) {
            user.setProperties(data.user);
        });
        user.set("user_id", user_id);
        return user;
    }
});

App.TwodRoute = Ember.Route.extend({
    model : function() {
        return App.Twod.findAll();
    }
});

While selecting each individual item works perfectly fine and fills the child outlet, it goes blank when the page is refreshed.

Do you have any insights on what might be causing this issue?

Answer №1

It appears there are two potential issues at play here.

Firstly, it seems that your URLs differ between the findAll and findBy functions. Is this intentional?

Secondly, while findAll returns an Ember promise (Ember.RSVP.Promise), findBy does not.

[UPDATE]: After reviewing the JSBin shared in the comments: http://jsbin.com/iPUxuJU/1/

The issue lies in the API endpoint which is returning an array in the user response, currently structured like this:

{user : [{ ... }] }

An ideal structure would be:

{user : {....} }

To address this, you can either modify the API endpoint or adjust your code to extract the first element from the array. Instead of:

user.setProperties(data.user);

You could try:

user.setProperties(data.user[0]);

For a revised JSBin example, see: http://jsbin.com/oquBoMA/1#/twod/2

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ajax is failing to show a success message for every registration input

After the user registers, I want to display a success message and clear the text boxes for the next registration. However, currently, the success message is only shown for the first registration. I want to display a success message for each registration. ...

Is there a way to enhance the Download File dialog with an additional option?

I want to develop an extension for a specific file type, and I'm interested in including a "Send to MyAddonName" feature in the download file dialog, alongside the "Open with" and "Save file" options. Just to clarify, I don't mean the Download Ma ...

In the realm of Javascript, the postAjax function fails to successfully post any content

Good day! I have been working on a small AJAX application, using this function as a foundation, with PHP as the server-side language. Below is the JavaScript code being employed: var data = {}; data.name = document.getElementById('name').value ...

What are some methods for saving HTML form data locally?

Creating an HTML form and seeking a solution for retaining user data even after closing and reopening the window/tab. Utilizing JavaScript cookies or HTML 5 local storage would require writing code for every input tag, which could be time-consuming especi ...

Ensuring the proper sequence of operations within a jQuery ajax callback function

I am facing an issue with my jQuery ajax function. The callback function includes two actions: 1) Taking the ajax result (which is an html form) and inserting it as the inner html of an html span. 2) Submitting this form How can I make sure that the form ...

A JavaScript function that instantiates an object that invokes its own function

Currently, I am working on an Angular service that is meant to return a new object. Everything seems to be fine and in working order. When I use new MakeRoll(), it successfully creates an instance. However, the issue arises when I call self.add towards th ...

Ways to verify audio in several HTML5 video files

I am working on a way to determine if multiple videos have audio or not. Here is an example of what I have so far: https://jsfiddle.net/hrd4a0c3/ However, my current solution only checks one video at a time. I am looking for a way to extend this functiona ...

RSS feed showing null xml data with jQuery

Working on coding a straightforward RSS feed utilizing jquery and pulling data from Wired. Everything appears to be functioning correctly, except for one issue - after the description, an unknown value of NaN is appearing in the result. It seems to be comi ...

Displaying text that follows the cursor on a JavaScript mouseover event

When I hover over the pin with my cursor, the text should move along with the mouse. However, the current position of the text is off and needs to be adjusted to be next to the pin. What is a more accurate way to calculate the correct position? var toolt ...

What are the steps for configuring clusters in an expressjs 4.x application?

I currently have an expressjs generated app that is configured with socket io and I want to incorporate nodejs clusters into it. However, the challenge lies in the fact that in Express 4.x, the server listening configuration now resides in the bin/www file ...

Troubleshoot PHP Debug and Ajax Notifications in Dropzone

I am currently utilizing the most recent release of Dropzone.js (3.7.1) in combination with a PHP script to handle file uploads to the server. I am interested in receiving a message within the drop zone area in case of an error. When I use the following c ...

What is the best way to maintain an active listGroup even after reloading the page?

I'm currently working on a gallery project using the #listGroup bootstrap component. I would like to ensure that when a user clicks on one of the albums, the active state of the #listGroup persists even after the page is reloaded or refreshed. How can ...

Tips for maintaining video height consistency while adjusting its attributes

When you click on a button, the video's poster and src attributes change. However, after clicking, the video height briefly becomes 0, causing an unsightly effect on the entire page. How can this be avoided? Please note - lorem.mp4 and ipsum.mp4 hav ...

The tooltip in chart.js stubbornly holds onto past data even after it's been

Utilizing chart.js, I have implemented a feature where a tooltip displays when a user hovers over the chart successfully. However, I encountered an issue. I added an option for users to un-check data-points, which works correctly. But now, the tooltip fun ...

Arranging information within an ExpansionPanelSummary component in React Material-UI

https://i.stack.imgur.com/J0UyZ.png It seems pretty clear from the image provided. I've got two ExpansionPanelSummary components and I want to shift the icons in the first one to the right, next to ExpandMoreIcon. I've been playing around with C ...

Customizing the appearance of charts in AngularJS using the Chart.js

I just started experimenting with AngularJS and recently created a horizontal bar chart using Chart.js and HTML. My next step is to make the chart dynamically appear on the page with the help of AngularJS. Can someone please provide some guidance on how I ...

Ensuring validity with Vuelidate for customizable fields

There's a form where fields are dynamically added on a click event. I want a validation error to appear when the field value is less than 9 digits after changing or blurring it. The issue is that since the fields are created dynamically with the same ...

What is the best way to set up an on-change listener for material-ui's <CustomInput...>?

I'm currently utilizing the React dashboard created by Creative Tim. I have a question regarding how to set up an onChange listener for a Here is the code snippet for the custom input class: import React from "react"; import classNames from "classna ...

Guide to configuring environment variables with Script [Node.js]

Is there a way to set an environmental variable using a script in node.js? I have a script that gives me the deployed solidity contract address and I need to use it in my .env file (I am using the dotenv module). I have been trying to figure out a way to ...

I am looking to incorporate a dropdown feature using Javascript into the web page of my Django project

According to the data type of the selected column in the first dropdown, the values displayed in the columns of the second dropdown should match those listed in the JavaScript dictionary below, please note: {{col.1}} provides details on the SQL column data ...