jQWidgets Forums

jQuery UI Widgets Forums Plugins Data Adapter Mapping to a JSON HAL response

This topic contains 1 reply, has 1 voice, and was last updated by  richardjansen 10 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Mapping to a JSON HAL response #60044

    richardjansen
    Participant

    Hi,

    Is it possible to use JSON HAL as dataAdapter data? I want to map this structure to my dataAdapter, like this, but with no success. Note that the response is not an array, but an object literal. The ‘_embedded.leverancier’ is the needed data array.

    Cheers Richard.

    datafields: [
        {name: 'id', map: '_embedded>leverancier>id'},
        {name: 'naam', map: '_embedded>leverancier>naam'}
    ],
    
    // REST response:
    {
    	_links: {
    		self: {
    			href: "https://myrul/leverancier/apotheek"
    		}
    	},
    	_embedded: {
    		leverancier: [
    			{
    				id: 1,
    				naam: "Tester",
    				_links: {
    					self: {
    						href: "https://myrul/leverancier/apotheek/1"
    					},
    					parent: {
    						href: "https://myurl/leverancier/apotheek"
    					}
    				}
    			},
    			{
    				id: 2,
    				naam: "Another tester",
    				_links: {
    					self: {
    						href: "https://myurl/leverancier/apotheek/2"
    					},
    					parent: {
    						href: "https://myurl/leverancier/apotheek"
    					}
    				}
    			},
    			{
    				id: 3,
    				naam: "Foo tester",
    				_links: {
    					self: {
    						href: "https://myurl/leverancier/apotheek/3"
    					},
    					parent: {
    						href: "https://myurl/leverancier/apotheek"
    					}
    				}
    			}
    		]
    	}
    }
    Mapping to a JSON HAL response #60046

    richardjansen
    Participant

    Solved it myself!. I use the ‘root’ property of the dataAdapter, like this:

    datafields: [
                {name: 'id'},
                {name: 'naam'}
            ],
            root: '_embedded>leverancier',
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.