cancel
Showing results for 
Search instead for 
Did you mean: 

Binding Nested JSON Model in XML View

huibin_lau
Participant
0 Kudos

Hi Experts,

I have a nested JSON model named salesOrderModel as below and I am trying to bind it to a list in a XML view to display all the product names in the "products" array.

{
	"orders": [
		{
			"orderId": 0,
			"orderName": "Order 1",
			"products": [
				{
					"productId": 0,
					"productName": "Product 1-A"
				},
				{
					"productId": 1,
					"productName": "Product 1-B"
				},
				{
					"productId": 2,
					"productName": "Product 1-C"
				},
				{
					"productId": 3,
					"productName": "Product 1-D"
				},
				{
					"productId": 4,
					"productName": "Product 1-F"
				}
			]
		}
	]
}

I am doing the binding in the XML view as below

<View
	xmlns="sap.m"
	xmlns:layout="sap.ui.layout"
	controllerName="test.View1">
	<Page
		title="{salesOrderModel>orderName}"
		navButtonPress="onNavBack"
		showNavButton="{device>/system/phone}">
		<content>
					<List id="products" 
						items="{salesOrderModel>/orders}"
						headerText="Products">
					<items>
						<StandardListItem title="{salesOrderModel>products/productName}" 
							type="Active"
							press="onSelectionChange"/>
					</items>
				</List>
		</content>
	</Page>
</View>

The binding path at runtime is incorrect.

How can I correct the path and display the correct information? Thanks.

Regards,

Hui Bin

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos
items="{salesOrderModel>/orders/0/products}"

<StandardListItem title="{salesOrderModel>productName}" type="Active"
							press="onSelectionChange"/>
huibin_lau
Participant
0 Kudos

I figured the solution out, thanks your comment helped!

Answers (4)

Answers (4)

0 Kudos

Hi huibin.lau,

The problem is in items give it as items="{salesOrderModel>/orders/0/products}"

and in standardListItem Title give it as title="{salesOrderModel>productName}"

and all these are case-sensitive if error is coming means its because of this reason.

please let me know once you have done.

0 Kudos

so what was the solution ? huibin.lau

huibin_lau
Participant
0 Kudos

Hi Sergio Guerrero,

I tried exactly as you said but at runtime the path is invalid.

Any idea what's wrong?

SergioG_TX
Active Contributor
0 Kudos

you should bind your List to the orders/products rather than the orders

						items="{salesOrderModel>/orders/products}"

then in your items remove products since you have binded that already

<StandardListItem title="{salesOrderModel>/productName}"