Issues with arrays in JQuery

The code snippet below appears to be not displaying anything, despite the fact that it should be. There are no errors being highlighted by Firebug.

            var assign = {
                'href' : {
                    '.voteUp' : '?p=action&a=voteup&pid='+ value.PostPID,
                    '.voteDown' : '?p=action&a=votedown&pid='+ value.PostPID,
                    '.postImage a': '?p=user&uid='+ value.UserUID
                },

                'src' : {
                    '.postImage img' : value.UserImage
                },

                'html' : {
                    '.repCount' : value.PostRep,
                    '.postInfo .rep': value.UserRep,
                    '.postInfo .name': value.UserName,
                    '.postInfo .time': value.PostTime,
                    '.postMessage' : value.PostText
                }
            };

            $.each(assign, function(type, data) {
                switch (type)
                {
                    case 'html':
                        $.each(data, function(handler, value) {
                            $('#'+ value.PostPID +' '+ handler).html(value);
                        });
                    break;

                    case 'href':
                    case 'src':
                        $.each(data, function(handler, value) {
                            $('#'+ value.PostPID +' '+ handler).attr(type, value);
                        });
                    break;
                }
            });

This portion of code is part of a larger script, with the remaining sections functioning properly (for instance, there is a function following this one that uses fadeIn for various contents). If you don't spot any issues here, please leave your feedback above and I will include the complete script. Thank you.

Answer №1

No objects contain a property named PostPID.

Given that value is referring to the object cited by html, src, etc., you must utilize a specific property within those objects to retrieve the correct value.

For instance:

case 'html':
    $.each(data, function(handler, value) {
        $('#'+ value['.repCount']+' '+ handler).html(value);
    });
break;

Alternatively, if you were seeking the different identifier for value (the origin of which was not provided in the query).

In such a scenario, modify the parameter name within the $.each() method to something else.

case 'html':
       // renamed the value parameter---v---to ensure access to the previous "value"
    $.each(data, function(handler, v) {
        $('#'+ value.PostPID+' '+ handler).html(v['.repCount']);
  // original----^        "each" parameter------^
    });
break;

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

The perplexing behavior of dynamic dropdowns in CodeIgniter

As I browse through various questions on dynamic dropdowns, I hope that my own inquiry will not be overlooked. Within a model, I have a method that retrieves data from a table and creates an array for constructing a codeigniter dropdown menu. <pre> ...

Is the array able to display results without including empty positions?

Attempting to create a triangle similar to Floyd's triangle, with the following pattern. 1 2 3 4 5 6 7 8 9 10 However, I made a mistake while practicing and unintentionally formed a different kind of triangle using this code: class Main { publi ...

the process of creating b3dm and pnts files

Currently exploring the 3d tiles branch from Cesium. Managed to successfully build it on my local setup and now delving into how custom tiles work. Having some trouble with viewing b3dm and pnts files as my editor displays weird characters in them. Any i ...

Automatically export SSRS reports to PDF using the default interface

In our organization, we utilize numerous custom SSRS reports that we typically run from the built-in interface. This interface allows users to set parameters and then click 'View Report' to generate a default HTML rendering of the report. A small ...

What is the method to disconnect clients using socket io?

I'm currently developing an application that allows clients to share real-time location data with one another using JavaScript. The issue I'm facing is that the data is being transmitted successfully on the server.js side, but it's not displ ...

Combining the elements of a nested array using AngularJS within a loop

I attempted to showcase the values of AngularJS. Now I aim to aggregate all these values into its parent variable sum. This is How my AngularJs Array Appears: { "isInternalInvoice":1, "name":"Invoices", "sum":50, "articles":[ { ...

The issue of Dojo AMD failing to load a custom module

Trying to develop a web application using the ArcGIS API, Dojo, and Flask. The goal is to create a "file uploads" dialog by defining it as its own module with the Dojo 1.7 AMD convention (i.e. "define"). Current file structure: \static home.js ...

Question about MongoDB Concurrency - Ensuring Atomicity with FindOne and FindOneAndUpdate operations

Before I proceed with coding, I kindly request your insights on a specific scenario I am trying to address. Despite reviewing numerous MongoDB documents and forums, I still seek clarity on how certain operations would be executed in my unique situation. ...

Preserve jQuery-enhanced webpage changes permanently

I am looking to permanently save modifications made on an HTML page using JQuery. I have come across suggestions about achieving this by sending an Ajax call and storing the data in a database table. However, I am unsure about what exactly needs to be save ...

A versatile multi-select jQuery widget featuring the ability to choose options within a specific opt

I am on the hunt for a cool jQuery tool that has the following characteristics: It enables you to create multiple groups, such as: Group 1 - Sub 1 1 - Sub 1 2 - Sub 1 3 Group 2 - Sub 2 1 Group 3 - Sub 3 1 - Sub 3 2 By clicking on Group 1, for instance, ...

Tips for modifying the height of a div using cssText with a JavaScript variable

let height = Math.floor((Math.random()*100)+50); document.getElementById("child").style.cssText="background-color: red; height: " + height + "px; width: 100px;"; ...

Using jQuery to reveal the following unordered list after an H3 element by sliding it

<h3>Details<span class="dropdown">View</span></h3> <div id="sbc"> <ul> <li><h2>Role: Supervisor</h2></li> <li>Manager Contact:</li> < ...

Firebase Database Integration with AngularJS: Loading Results Dynamically upon Button Click or Action

Even though I can successfully retrieve data from my Firebase database, the scopes in my AngularJS application aren't updating automatically. It seems like the issue lies within AngularJS, but I'm unable to pinpoint the exact cause. Below is the ...

Looking for the best JSON database library?

Currently utilizing Node.js... Personally, I find SQL to be unappealing. My preference lies with JSON, as I desire to store my server data in that format. While I can utilize JSON.parse and .stringify, it seems like a suboptimal approach for larger appli ...

Storing the result of browser.executeScript in a variable with Protractor

I'm facing a challenge in storing the value of browser.executeScript within a local variable in my it block. In some cases, it returns null which is not desired. I've experimented with different approaches but haven't found a reliable solut ...

Issue with Bootstrap's form-inline element causing incorrect spacing in btn-group

I'm having an issue with Bootstrap components. When I try to input numbers, everything works fine as long as I don't use form-inline or a navbar. Check out my fiddle here: http://fiddle.jshell.net/6Lrhcezb/ https://i.sstatic.net/hzmlM.png The ...

When a radio button is checked, add a class to its parent element that has a specific class assigned to it

In order to dynamically add a class to a specific div element higher up the DOM hierarchy when a radio button is clicked, I am in need of assistance. There are multiple instances of these div elements with different radio buttons, so it is crucial that on ...

What is the best way to invoke a Symfony function in a controller using AJAX?

I am looking to utilize ajax to call a function within my controller. As a novice, I am struggling to comprehend the necessary steps for this task. /** * @Route("/Article/{id}/{vote}", name="article_vote") */ public function vote($id ...

Exploring FHIR data with Java and JSON

As I delve into querying FHIR resources, my focus is on utilizing a REST interface. After studying the details provided on the Search page, I have come to understand that there are 7 distinct search parameter types (NUMBER, DATE, STRING, TOKEN, REFERENCE, ...

Add a fresh category to a JSON document

Combining Express (Node.js) and Mongoose, I am developing a REST API and attempting to implement JWT token-based login. However, I have encountered an issue. Upon executing the code below: const mongoose = require('mongoose'); const User = mongo ...