Ember's ability to bind custom objects in a unique way

Take a look at this twiddle:

Essentially, in my `crit-service`, I am creating Ember Objects called "Crits" and "Crit", and populating them with data.

The `crit-service` is being utilized by two different components that have similar functionalities: displaying the Crits.

The issue I'm facing is that the "change" buttons are not functioning as expected. Even though I can see through debugging that the values are being changed, the view does not reflect these updates. Why is this happening? Shouldn't updating a value in an Observable Ember Object automatically notify the template of the changes? And most importantly, how can I resolve this problem?

P.S. I've come across a workaround involving the use of Ember.A() instead of Objects. However, this approach would introduce unnecessary boilerplate since my data model primarily consists of objects rather than arrays of key-value pairs.

Answer №1

This issue appears to be related to the {{#each-in}} helper not refreshing on changes. A simple workaround is to utilize the {{get}} helper instead.

Instead of:

{{#each-in obj as |key val|}}
  {{key}}={{val}}
{{/each-in}}

Try this:

{{#each-in obj as |key|}}
  {{key}}={{get obj key}}
{{/each-in}}

Keep in mind that this approach may not handle additional properties being added.

Check out this functional twiddle with the fix implemented.


An alternative solution that will consistently work is to execute .rerender() on the component. This method leverages glimmer, which only updates specific parts of the DOM that have changed. Just remember to invoke it on the shared root component or both individual components.

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

What is the best way to alter something based on the current date?

My goal is to dynamically change a message based on how close a specific date is. The objective is to update an element of a webpage to display "Renewal Unnecessary" when the date is more than 3 months away, "Renewal upcoming" when the date is less than 3 ...

Using .prev in conjunction with a Meteor event

Yesterday I inquired about how to remove the input preceding my button, as mentioned here: How to remove the input element before my button?. I received a solution that worked in the snippet provided. However, when trying to implement it in my event, I fou ...

JSON Schema: ensuring that all elements within an array are distinct and not null

I am currently in the process of developing a JSON schema that needs to meet the following criteria: The schema must declare a top-level object with at least one property Each property's value should be an array, with each array containing exactly N ...

Is there a different way to invoke PHP within JavaScript?

Is it possible to include PHP code in JavaScript? I have come across information stating that this practice is not recommended: document.getElementById('id1').innerHTML="<?php include my.php?>"; If including PHP directly in JavaScript is ...

Retrieving JSON data by parsing through specific keys$values

If I only want to list the objects with a particular key-value (like gender) from the JSON array fetched and rendered by this code, where should that filtering process occur - during the fetch or the render? const URL = "https://ghibliapi.herokuapp.com/ ...

When using Vue.js, the v-bind:class directive can be applied when an array is present and contains a specific

In my current project with Laravel and Vue.js, I am dealing with the task of creating multiple users. To accomplish this, I am constructing an array of users and populating all the necessary fields in order to store them in a database table. Once all field ...

Display Vue component using a string input

Is there a solution to make this non-functioning example work, or is its usage illegal? Vue.component('hello', { template: '<span>Hello world!</span>' }) Vue.component('foo', { data(){ return { ...

Node.js, Express continues to execute an if statement even if the condition is false

My goal is to determine whether the user signed in is an admin or not. User data is structured like this: [ { "isAdmin": "true", "_id": "60c6df22f25d381e78ab5f31", "name": "Admin", ...

Implement a function to delete an item from an array within a React object by utilizing the UseState hook

I am facing a challenge in React as I attempt to remove an element from an array within an array of objects using the UseState hook. Despite my efforts, the interface does not re-render and the object remains in place. From what I understand, in order for ...

Conceal a div element dynamically when clicking on another div

<script type="text/javascript"> function displayBookInfo(str) { if (str == "") { document.getElementById("more-info").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for m ...

Sending documents via ExpressJS

I'm currently developing a small application using the latest NodeJS and ExpressJS, but I've encountered an issue with uploading files. My routes are set up like this: app.get('/Share', share.index); app.post('/Share/Process&apos ...

What is the best way to invoke a Service from a Directive in AngularJS?

Every time a user clicks, a directive is triggered to change the icon for adding to their favorite list. View: <div class="col col-33"> <i class="icon ion-ios-heart-outline" favorite="place[0].objectId" on-icon="ion-ios-heart-outline" off-ic ...

What is the best method for connecting my HTML to jQuery code?

Apologies for my lack of experience in coding, but I will try to keep this brief. To put it simply, when I insert my jQuery code directly into the HTML file below the content, it works perfectly - the element I want to animate 'hides' and then & ...

Running a code from a plugin in Wordpress site

I am currently utilizing the "wp-video-lightbox" plugin for WordPress, which generates small floating boxes for my videos. I am interested in incorporating variables like http://www.example.com/?video3 to provide shortcuts similar to what YouTube offers. ...

Encountering a 'TypeError: app.address is not a function' error while conducting Mocha API Testing

Facing an Issue After creating a basic CRUD API, I delved into writing tests using chai and chai-http. However, while running the tests using $ mocha, I encountered a problem. Upon executing the tests, I received the following error in the terminal: Ty ...

If the <span> element contains text, then apply a class to the <i> element

Is there a way to target a different i element with the id 'partnered' and add the class 'checkmark'? $(document).ready(function () { jQuery('span:contains("true")').addClass('checkmark'); }); The current code su ...

What is the best way to conceal the button?

I'm working on a program that involves flipping cards and creating new ones using three components: App, CardEditor, and CardViewer. Within the CardEditor component, I am trying to implement a function that hides the button leading to CardViewer until ...

Having trouble creating an angularjs table using ng-repeat in the controller?

I have a sample snippet that I would like to discuss. My goal is to display a JSON object in an angular table using ng-repeat, which is being generated from my angular controller script. I have attempted the code below, but for some reason, the table is no ...

What issue is being encountered with this JavaScript generated by PHP?

PHP on the host generates JavaScript code that results in an error stating: missing ; before statement The generated JavaScript code looks like this: try{ obj = document.getElementById('subcat'); }catch(e){} try{ obj.innerHTML = ...

How to integrate a custom service worker in create-react-app without the need for ejecting

I have an app that I want to switch over to React. I've created a new version of the app using create-react-app (with react-scripts 1.0.13) to mimic the functionality of the existing app. The challenge I'm facing is integrating the existing serv ...