Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Streety 358 posts 568 karma points
    Apr 10, 2014 @ 12:54
    Streety
    0

    Output Nodes in Json format

    Hello,

    I have been given the task to Umbraco-fy a page which is basically static in nature and has a javascript quotes process which uses hard coded values in a json array:

     

        var fitted = {
            3sqm: {
                green: 250,
                blue: 290,
                red 330,
                pink: 640,
                green: 575,
                black: 275
            },
            5sqm: {
                green: 250,
                blue: 290,
                red: 330,
                pink: 640,
                green: 575,
                black: 275
            },
            8sqm: {
                green: 237.50,
                blue: 275.50,
                red: 313.50,
                pink: 608,
                green: 546.25,
                black: 261.25
            }
        };

    I have created the umbraco doc types and populated with data.

    I have a razor script that outputs the data in JSON format but I can't get it right.

        @{

    var items = new List<dynamic>();

    foreach (var products in node)
    {

    var rangename = @products.GetPropertyValue("color");
    var fcpm1 = @products.GetPropertyValue("3sqm");
    var fcpm2 = @products.GetPropertyValue("5sqm");
    var fcpm3 = @products.GetPropertyValue("8sqm");


    items.Add(new
    {
    productName = rangename,
    title1 = fcpm1

    });

    }

    var o = new
    {
    items = items
    };

    string json3 = Json.Encode(o);

    };

    @Html.Raw(json3)

    I get this output whcih is wrong:

    {"items":[
    {"productName":"green","title1":"250"},
    {"productName":"blue","title1":"290"},
    {"productName":"red","title1":"330"},
    {"productName":"pink","title1":"640"},
    {"productName":"blue","title1":"575"},
    {"productName":"black","title1":"275"}
    ]}
    {"items":[
    {"productName":"green", "title1":"250"},
    {"productName":"blue","title1":"290"},
    {"productName":"red","title1":"330"},
    {"productName":"pink","title1":"640"},
    {"productName":"blue","title1":"575"},
    {"productName":"black","title1":"275"}
    ]}

     

    The first problem is that each color needs to be represented with a value within the group. At the moment it has two value pairs.

    Any help to get it in the right format would be really helpful.

     

    Thanks

     

  • Streety 358 posts 568 karma points
    Apr 11, 2014 @ 13:48
    Streety
    0

    Any ideas

     

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Apr 21, 2014 @ 18:03
    Steve Morgan
    0

    I don't believe it's clear what you're trying to do.

    Am right in thinking that you have a list of products which have a colour and size attribute the editors can set - depending on the selected product you need to get the correct numeric value which you need to look up from the static list (which you're keeping in different nodes?).  

    What would a correct output look like?

     

     

Please Sign in or register to post replies

Write your reply to:

Draft