rsanchez / json

Output ExpressionEngine data in JSON format.
http://devot-ee.com/add-ons/json/
100 stars 236 forks source link

Categories #17

Closed nate8684 closed 12 years ago

nate8684 commented 12 years ago

I'm trying to pull categories via this JSON extension. I found out how to do so with this: https://github.com/rsanchez/json/issues/7. When I pull the source to my page I can see that it is fetching the categories, but my code isn't pulling them to my external source. For instance, the code below will fetch everything but category_group, and I assue you that isn't empty. Take a look below:

Template Code: {exp:json:entries channel="gathering" show_categories="yes" fields="title|url_title" }

Template Output: http://www.lcbcchurch.com/mobileJSON/gatherings

External Code trying to pull the JSON:

    $('.loading-wrapper').append('<div class="loading">Your page is loading…</div>');

    $.ajax({        
            url: "http://www.lcbcchurch.com/mobileJSON/gatherings",
            dataType: "json",
            success:function(data){
                eventResults(data);
            }
            });

        function eventResults(data) {
            for(var i = 0; i<data.length;i++){
                    $(".gathering").append("<a href='#"+data[i]["url_title"]+"' class='campus' rel='external'><h1>"+data[i]["title"]+"</h1>"+data[i]["category_group"]+"");

            }
            $('.loading-wrapper').empty();
            // Call the pics ready function

            }

Thoughts?

rsanchez commented 12 years ago

try console.log(data) where you have eventResults(data), and then paste the result from your console here.

nate8684 commented 12 years ago

[ Object categories: Array[4] entry_id: 544 title: "More than Ordinary" url_title: "more-than-ordinary" proto: Object defineGetter: function defineGetter() { length: 2 name: "defineGetter" proto: function () { defineSetter: function defineSetter() { length: 2 name: "defineSetter" proto: function () { lookupGetter: function lookupGetter() { length: 1 name: "lookupGetter" proto: function () { lookupSetter: function lookupSetter() { length: 1 name: "lookupSetter" proto: function () { constructor: function Object() { create: function create() { defineProperties: function defineProperties() { defineProperty: function defineProperty() { freeze: function freeze() { getOwnPropertyDescriptor: function getOwnPropertyDescriptor() { getOwnPropertyNames: function getOwnPropertyNames() { getPrototypeOf: function getPrototypeOf() { isExtensible: function isExtensible() { isFrozen: function isFrozen() { isSealed: function isSealed() { keys: function keys() { length: 1 name: "Object" preventExtensions: function preventExtensions() { prototype: Object seal: function seal() { proto: function () { hasOwnProperty: function hasOwnProperty() { length: 1 name: "hasOwnProperty" proto: function () { isPrototypeOf: function isPrototypeOf() { length: 1 name: "isPrototypeOf" proto: function () { propertyIsEnumerable: function propertyIsEnumerable() { length: 1 name: "propertyIsEnumerable" proto: function () { toLocaleString: function toLocaleString() { length: 0 name: "toLocaleString" proto: function () { toString: function toString() { length: 0 name: "toString" proto: function () { valueOf: function valueOf() { length: 0 name: "valueOf" proto: function () {

That's just one of the objects expanded. Does that help? Thanks!

rsanchez commented 12 years ago

OK. Categories is an array, so you actually want to do this:

+data[i]["categories"][0]["category_group"]+
nate8684 commented 12 years ago

Thanks, that worked perfectly!