1

It seems that the following code doesn't print anything, while, as you can see, it should. Basically there are no errors reported 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 is part of other code, but the rest of the script works well (for example, after this code there is a function that fadeIn the contents). If you cannot find anything bad here, please comment above and i'll add the entire script. Thanks.

1 Answer 1

2

None of the objects have a PostPID property.

Since value represents the object referenced b html, src etc., you need to use a property in those objects, to get the proper value.

For example:

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

Or perhaps you wanted the other value identifier (the source of which is not included in the question).

In that case, rename the parameter for the $.each() handler to something else.

case 'html':
       // renamed value paramter---v---to make the previous "value" accessible
    $.each(data, function(handler, v) {
        $('#'+ value.PostPID+' '+ handler).html(v['.repCount']);
  // original----^        "each" parameter------^
    });
break;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.