Ember's structured format featuring objects as rows and column names as properties

I am currently working on developing a modular tabular form that requires an input of two arrays: one containing objects (representing the rows) and another containing property names of those objects (representing the columns). The goal is to be able to modify these properties using Ember.TextFields within the form.

Unfortunately, I'm facing difficulties in achieving this functionality. While I can retrieve the values of the properties (as demonstrated in the code snippet below), they are raw values and not references. Therefore, the bindings to these values do not update the properties of the objects as intended.

View

App.SomeTabularForm = Em.View.extend({
  template: <see below>,

  things: [
    Em.Object.create({ foo: 'a', bar: 'b' }), 
    Em.Object.create({ foo: 1, bar: 2 })
  ],
  fieldNames: ['bar', 'foo'],

  thingsWithFields: function() {
    var fieldNames = this.get('fieldNames');

    var thingWithFieldsProxy = Em.ObjectProxy.extend({
      fields: function() {
        var thing = this;

        return fieldNames.map(function(fn) {
          // FIX: this returns a raw value which is not bindable in a template
          return thing.get(fn);
        });
      }.property()
    });

    return this.get('things').map(function(t) {
      return thingWithFieldsProxy.create({ content: t });
    });
  }.property('things.[]', 'fields.[]')
});

Template

<table>
  <tr>
    {{#each view.fieldNames}}
      <th>{{this}}</th>
    {{/each}}
  <tr>

  {{#each view.thingsWithFields}}
    <tr>
      {{#each fields}}
        <td>
          {{! FIX: does not actually bind to thing's property }}
          {{input type="text" valueBinding="this"}}
        </td>
      {{/each}}
    </tr>
  {{#each}}
</table>

Answer №1

To properly display content, make sure to specify the template name:

App.SomeTabularForm  = Em.View.extend({
  templateName: "mytemp",
....

Here is an example of the specified template:

<script type="text/x-handlebars" data-template-name="mytemp">
    {{blah}}
    <table>
  <tr>
    {{#each view.fieldNames}}
      <th>{{this}}</th>
    {{/each}}....

For more guidance, you can refer to this link.

If you prefer using the template property instead, follow this structure:

App.SomeTabularForm  = Em.View.extend({
    template: Em.Handlebars.compile("<div>{{#each field in view.fieldNames}}{{field}}<br/>{{/each}}</div>"),

  things: [...

You can also check out this example for reference.

If you are integrating it with routing, remember to adjust the view's name as shown in this demo.

EDIT

In order to bind to proxy objects properly,

The template should be updated like this:

{{#each view.thingsWithFields}}
    <tr>

        <td>
          {{! FIX: does not actually bind to thing's property }}
          {{input type="text" valueBinding="content.bar"}}{{input type="text" valueBinding="content.foo"}}
        </td>

    </tr>
      {{/each}}

Refer to this updated link for more information.

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

Just beginning my journey with Laravel alongside Vue.js and encountering the error message "Property or method is not defined on the instance but referenced during render."

Upon loading the page, all that can be seen is an empty screen following the brief appearance of {{greeting }}. Still getting acquainted with Vue, I decided to give it a go in laravel, so I put together a basic blade template: <!DOCTYPE html> <htm ...

Eliminate unnecessary CSS classes from libraries such as bootstrap when working on a React project

Our team is currently in the process of developing a React project that involves webpack and babel. Our goal is to automatically remove any unused CSS classes from CSS frameworks Bootstrap and AdminLTE 2, which are integral parts of our project. For this ...

The useRouter() function doesn't seem to be successfully navigating to the main landing page

"use client" import { useState } from 'react'; import {auth} from '../../firebase-config' import {createUserWithEmailAndPassword} from 'firebase/auth' import { useRouter } from 'next/router'; const SignUp = ...

Leveraging both onmouseover and onmouseout for container expansion

My goal is to utilize JavaScript along with the HTML events "onmouseover" and "onmouseout" to create a dynamic container. Essentially, I want the container to act as simply a heading when the mouse is not hovering over it, but expand to display additional ...

Is there a way to convert this asynchronous function into a synchronous one so that it returns the value immediately

When it comes to making a Nodejs/Javascript method synchronous, there are several solutions offered by the community. Some suggest using libraries like async and fibrous, but these involve wrapping functions externally. However, I am in search of a soluti ...

Calculate the number of arrays in an object and then substitute them

Currently, I have an object that is returning the following data: Object {1: 0, 2: Array[2], 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0} My goal is to replace the "Array[2]" with just the number "2" (indicating how many records are in ...

React UseEffect does not trigger update upon deletion of data from array

I've hit a roadblock and need some assistance. I'm working on a MERN stack application that interacts with the Github API. Users can search for Github users, save them to their profile on the app, and automatically start following them on Github. ...

Property computation being initiated before property initialization

I am encountering an issue in my Vue application where I am trying to filter an array received from map getters based on a type prop within a computed property. Despite verifying that both the array elements and the prop are strings, the filtering process ...

The responsiveness of Angular Material appears to be limited when tested in Chrome's debug mode for different devices

I have come across a peculiar issue. Within my HTML file, I have defined two attributes: Hide me on small devices Hide me on larger than small devices When I resize the window, the attributes work as intended. However, when I enter device debug mode ( ...

Guide to adding new data to a JSON array

I'm currently working on implementing a punishment system using discord.js where the actions taken against users are logged by the Discord bot in a JSON file. The structure of the punishment data is as follows: { "username": "baduser# ...

Examining the potential of a promise within a dynamic import feature in Angular

Here's a code snippet that I'm working with: The component file (component.ts) looks like this: async ngOnInit() { import('dom-to-image').then(module => { const domToImage = module.default; const node = document.getEl ...

Perform time update every second

Is it feasible to have my timeupdate function run every second? (Using VUE CLI) @timeupdate="videoSecond" videoSecond(){ let Second = this.player.currentTime(); let CaptureList = this.capturesList; CaptureList.forEach(element => ...

I am having trouble scrolling through the main content when the side-drawer is open. How can I fix this issue?

When the sidebar is opened, I am facing issues with the main content scroll and certain fields such as select options and search bar not functioning properly. I have included the main content in the routes from which it is being loaded. However, the scroll ...

Finding a solution to the type issue of error handling in Route Handler with NextJS

I'm working on a route handler located at app/api/transactions/route.ts. Here's a snippet of the code: import { NextRequest, NextResponse } from "next/server"; import { AxiosError } from "axios"; import axios from "../axi ...

Modifying SASS variable values based on the presence of specific text in the page URL

How can I utilize the same SASS file for two different websites with similar functionality but different color schemes? My goal is to dynamically change the color based on the URL of the page. However, I am facing challenges in extracting the page URL from ...

Tips for presenting validation messages from the server on the client side using react-query

Hey there! I have set up the Express route for the signup API call, which is functioning correctly on the server-side. However, my goal is to show these validation messages in real-time as the user inputs their credentials on the React client side app.post ...

Maintain the newly selected background color for the current day in fullcalendar when navigating to the next or previous month

Currently, I am working on a project in React using npm fullcalendar. One of the requirements is to change the color of the current day. After some trial and error, I was able to achieve this by adding the following code: $('.fc-today').attr(&ap ...

Manipulate text with jQuery

Is there a way to remove 'http://' or 'https://' from text using javascript? I am looking for regex solutions as well. This is what I have tried so far: JSFIDDLE HTML: <div class="string"></div> JS: $text = $('.s ...

Utilizing Google Maps API to automatically set an address on page load

As a beginner in using the Google Maps API, I have successfully integrated a Google Map into my project. However, I am struggling to figure out how to set specific addresses on the map. I have a list of 2,000 entries in a database, each including an addres ...

When trying to use `slug.current` in the link href(`/product/${slug.current}`), it seems to be undefined. However, when I try to log it to the console, it is displaying correctly

import React from 'react'; import Link from 'next/link'; import { urlFor } from '../lib/clients'; const Product = ({ product: { image, name, slug, price } }) => { return ( <div> <Link href={`/product/ ...