Copied to clipboard

Flag this post as spam?

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


  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Oct 09, 2014 @ 15:40
    Søren Kottal
    0

    Get children where some json property is true.

    I have a node with a property containing some json data. Ie:

    {
    isThisIt: true;
    isThisSomethingElse: false;
    }
    

    Can I query that node like this?

    Model.Content.Children.Where(x => x.propertyName.isThisIt)

     

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Oct 09, 2014 @ 15:46
    Jeroen Breuer
    100

    Hello,

    You need to convert the JSON to an object before you can query it. You can use a property value converter for this. Here is an example for the Image Cropper which also stores JSON: https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/blob/master/Umbraco.Extensions/PropertyConverters/ImageCropperConverter.cs

    Jeroen

  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Oct 09, 2014 @ 15:51
    Søren Kottal
    0

    Thanks - looks like i'm going to learn something new to day :)

  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Oct 13, 2014 @ 08:00
    Søren Kottal
    0

    Do you have an example of how you query things? Not sure if I am doing it right.

     

    var node = new DynamicNode(1);

    var children = Umbraco.Content(node.Descendants("DocTypeAlias").First().Id).Children.Where(x => x.propName.jSONProp = "something")

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Oct 13, 2014 @ 09:16
    Jeroen Breuer
    0

    You shouldn't use DynamicNode because it's legacy code. Try using Umbraco.TypedContent. You can find some examples with Descendants and GetPropertyValue here: http://our.umbraco.org/documentation/Reference/Mvc/querying

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies