Advice hooking things up

37 views
Skip to first unread message

Christos Jonathan Seth Hayward

unread,
Apr 3, 2014, 11:56:15 AM4/3/14
to ang...@googlegroups.com
I have something that should be showing a lot of data that is not showing any data.

In my HTML I have:

        <div ng-controller='OutputController'>

            <div ng-repeat='user in data.users'>

                <div ng-repeat='monologue in data.monologues[user]'>

                    <span class='text' ng-bind='monologue.text'></span>

                    <span class='timestamp' ng-bind='new Date(monologue.        timestamp).toLocaleString()'></span>

                </div>

            </div>


In my JavaScript I have:


           var repeatEr = function(data, status, headers, config)

                {

                var interval = 1000;

                angular.extend($scope, data);


In the data being sent to my page I have:


{"monologues": {"jonathan...@pobox.com": [["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ... }, "users": ["jonathan...@pobox.com"]}

What is happening is that it is displaying empty results.

What I intend for it to do is to pull the Ajax data it is pulling, and then display the text ("False" here) and timestamps in successive DIV's.

Given the data as I have it, what should I be doing with the repeaters so that it is displaying results accordingly?
--Or--
Given the repeaters I have, what should I be populating as data so that the repeaters will have what they need?

Thanks,


--
Christos Jonathan Seth Hayward
Christos Jonathan Seth Hayward, an Orthodox Christian author.

Amazon / Kindle • Author • Author Bio • Email • Facebook • Fan Page • Google Plus • LinkedIn • Professional • Twitter • Web • What's New?

If you read just one of my books, you'll want The Best of Jonathan's Corner.

Christos Jonathan Seth Hayward

unread,
Apr 3, 2014, 3:31:09 PM4/3/14
to ang...@googlegroups.com
To ask a slightly more focused question:

At present my data is being sent as {"monologues": {"jonathan...@pobox.com": [["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], ["False", 0.0], 
...]
}, "users": ["jonathan...@pobox.com"]}

On SO someone suggested I have something that looks like [{"monologues": {... etc etc ...}}].

Is my data structured appropriately for the repeater? I want to send a dictionary containing a list of strings [perhaps email addresses] for a key of "users", and a hash mapping strings [perhaps email addresses] to lists for "monologues".

Does my approach make sense, and/or can I appropriately modify either my repeaters and/or the JSON data so that the page will read a list of email addresses, and then look up lists of lists for each email?

Luke Kende

unread,
Apr 4, 2014, 1:24:22 AM4/4/14
to ang...@googlegroups.com
I have to admit, it's hard to follow what you are trying to do.  Have you spent much time understand Javascript object notation (JSON)?  It looks like the core of your difficulty is understanding effective data structures.

Also, if you can create a plunker to demonstrate, that makes it easier for the rest of us to see your issue and provide examples of how we might approach the task.

Using ng-repeat is great with arrays, and though it can be used on objects as well, I'd recommend sticking with arrays.  So, based on your original post (with a little cleaning up), I'd have my data structured like this:

$scope.data ={
   users = [
      { 
         'name': 'Bob',
         'email': 'som...@somewhere.com',
          monologues: [
             { 
                  user_id: '001' ,
                  text: 'Some text for the monologue',
                  timestamp: '0.0'  /./not sure how you are creating a Date from this - if you need it to be a new Date() then loop through data and do it before binding to scope
             },
             { ... more objects matching structure above... }
          ]
      }
   ]
}

<div ng-controller='OutputController'>

            <div ng-repeat='user in data.users'>

                <div ng-repeat='monologue in user. monologues'>

                    <span class='text' ng-bind='monologue.text'></span>

                    <span class='timestamp' ng-bind='monologue.timestamp'></span>

                </div>

            </div>

    </div>


Hope that gives you some direction.

Christos Jonathan Seth Hayward

unread,
Apr 4, 2014, 11:16:59 AM4/4/14
to ang...@googlegroups.com
My data structures might be hard to understand, but I've had graduate level coursework in data structures and a master's in applied math. Your suggestion regarding another way of structuring the data makes sense, but given your restructuring, I don't yet see confusion regarding data structures in having a list of users and a hash of lists of monologues on a per-user basis.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Apr 4, 2014, 11:30:33 AM4/4/14
to ang...@googlegroups.com

Hi,

My data structures might be hard to understand, but I've had graduate level coursework in data structures and a master's in applied math. Your suggestion regarding another way of structuring the data makes sense, but given your restructuring, I don't yet see confusion regarding data structures in having a list of users and a hash of lists of monologues on a per-user basis.

Wow, you must be crazy smart ;)

You did:
angular.extend($scope, data);

that means your merged your data into your scope right?
It seems to me then you need to do this:

   <div ng-repeat='user in users'>
       <div ng-repeat='monologue in monologues[user]'>

But then again, what do I know.

Regards
Sander

Luke Kende

unread,
Apr 4, 2014, 12:22:50 PM4/4/14
to ang...@googlegroups.com
I have a degree in CS (not that comparing penis sizes here matters :), but Javascript is a different beast.  If you want to use arrays like dictionaries (which we don't call them that in js - sounds like python), be sure to understand that an email address as an index is not a great idea.  Here's something to consider:

var data = {
  user: {
    name: 'bob' 
  }
}

you can access object values with dot syntax as well as array/dictionary syntax:

data.user.name == data['user'].name == data['user']['name']; //true

On your nested ng-repeats, it's going to be a challenge to reference the detached monologues by an index of the email address from the user object (not impossible).  At the least I would keep it simple by using another way to reference monos belonging to the user. 

good luck!



--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/8xN-TP_EIpc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages