Copied to clipboard

Flag this post as spam?

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


  • HuaweiP9User 31 posts 122 karma points notactivated
    May 18, 2018 @ 12:42
    HuaweiP9User
    0

    nuPicker JSON on view

    nuPicker JSON, I success get the data and I can see data in backofice but I have a problem. I want to use nuPicker dropdown (or values) in Razor view but I have a problem (couldn't appear). So my idea is because I will use this as a composition to pick a value from that and save that value (may be blog post), and all blog posts will have a diff values picked from nuPicker, and I want to display full list of nuPicker JSON at view as I told before, and use some jQuery or something like this to filter.. (also I have try to show picked up value but no success).

    Can u show me the correc way ?

    @Umbraco.AssignedContentItem.GetPropertyValue("nameOfCompositionProperty")
    
  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jun 28, 2018 @ 23:13
    Hendy Racher
    2

    Hi, if I understand, you want to use all the key/values in the razor view, not just the picked ones ?

    ModelsBuilder should return a nuPickers.Picker object, otherwise you should be able to do the following:

    var picker = Model.Content.GetPropertyValue<nuPickers.Picker>("nameOfCompositionProperty");
    

    Then you can use this to get at the collections:

    var allKeyValues = picker.GetEditorDataItems();
    var pickedKeyValues = picker.GetPickedEditorDataItems();
    

    There's a wiki page about this Picker model. An example there shows the PickedKeys property, but there should probably be an AllKeys property too !

  • HuaweiP9User 31 posts 122 karma points notactivated
    Jun 29, 2018 @ 19:50
    HuaweiP9User
    0

    Thanks Handy, I'll try this later. Yes, the idea was in backoffice I will pick one value. But in razor view I want to show all values in dropdown as options and this will be some kind of filter. Ex. if in backoffice composition I select value from picker - TEST1 and save, and after that when I go to the razor page where will be the full picker (with all values) and I select TEST1 from the options I want to show the content that is matched.

  • HuaweiP9User 31 posts 122 karma points notactivated
    Jul 03, 2018 @ 09:45
    HuaweiP9User
    0

    This doesnt work for me :/

    With this I can get the selected value from dropdown

    @{ var pickedItems = Model.Content.GetPropertyValue

      @foreach (var item in pickedItems.PickedKeys) { < li >@item< /li > }

    }

    and now only that is needed is how can I populate dropdown with all values from the pickerTest (not only selected)

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jul 03, 2018 @ 09:53
    Hendy Racher
    0

    Hi, your pickedItems variable is a nuPickers.Picker object, this has the method GetEditorDataItems() which will return all key/value pairs (not just the picked ones).

    var picker = pickedItems; // (I can't see the alias for the GetPropertyValue)
    
    foreach(var editorDataItem in picker.GetEditorDataItems())
    {
        var key = editorDataItem.Key;
        var label = editorDataItem.Label;
    }
    

    HTH, Hendy

  • HuaweiP9User 31 posts 122 karma points notactivated
    Jul 03, 2018 @ 10:38
    HuaweiP9User
    0

    @{ var pickedItems = Model.Content.GetPropertyValue

    I don't know why alias does not appear here but the alias is test1Picker

  • HuaweiP9User 31 posts 122 karma points notactivated
    Jul 03, 2018 @ 10:42
    HuaweiP9User
    0

    and this is what I get

    System.NullReferenceException: 'Object reference not set to an instance of an object.'

    on picker.GetEditorDataItems()

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jul 03, 2018 @ 10:52
    Hendy Racher
    0

    Hi, what version of nuPickers are you using ? (this method was added in v1.6.0)

  • HuaweiP9User 31 posts 122 karma points notactivated
    Jul 03, 2018 @ 11:01
    HuaweiP9User
    0

    I'm using 1.7.0.

    Can u writee full code (first for getting only selected which I have right now), and after that all values

Please Sign in or register to post replies

Write your reply to:

Draft