英文:
How to show array inside of other object array in Collection View Xamarin Forms
问题
I have a JSON response
{
"_id" : ObjectId("634b6be99237b35a9aa80dd5"),
"updatedAt" : ISODate("2022-10-16T02:27:44.766+0000"),
"createdAt" : ISODate("2022-10-16T02:26:49.276+0000"),
"firstName" : "Romulo",
"lastName" : "Calderon",
"email" : "romuloacd@gmail.com",
"phone" : "0962908538",
"description" : "Hoy u",
"user" : ObjectId("5aee09ef88b9ac4289109574"),
"appoinmentAt" : ISODate("2022-10-17T14:00:00.000+0000"),
"status" : [
{
"createdAt" : ISODate("2022-08-22T20:15:48.672+0000"),
"value" : "DEUDA",
"name" : "WITHOUT_PAYING"
},
{
"createdAt" : ISODate("2022-08-22T20:15:48.672+0000"),
"value" : "PAGADO",
"name" : "PAID_OUT"
}
],
"total" : 45.36,
"iva" : NumberInt(12),
"value" : 40.5,
"time" : NumberInt(30),
"__v" : NumberInt(0)
}
from an API call, I already show the most fields in collection without any problem, but I have inside the response another array defined in this model:
namespace App1.Models
{
public class TicketsApi
{
[JsonProperty("_id")]
public string Idtickets { get; set; }
[JsonProperty("user")]
public string Idusuario { get; set; }
[JsonProperty("firstName")]
public string Nombresolicitante { get; set; }
[JsonProperty("lastName")]
public string Apellidosolicitante { get; set; }
[JsonProperty("email")]
public string CorreoSolicitante { get; set; }
[JsonProperty("description")]
public string Motivoconsulta { get; set; }
[JsonProperty("phone")]
public string CelularSolicitante { get; set; }
[JsonProperty("value")]
public string ValorSolicitante { get; set; }
[JsonProperty("time")]
public string TiempoSolicitante { get; set; }
[JsonProperty("status")]
public Estado[] Status { get; set; }
[JsonProperty("appoinmentAt")]
public DateTime CitaSolicitante { get; set; }
[JsonProperty("createdAt")]
public DateTime FechaCreacion { get; set; }
}
public class Estado
{
[JsonProperty("value")]
public string EstadoPago { get; set; }
[JsonProperty("name")]
public string EstadoTransaccion { get; set; }
}
}
In the front I have this xaml code, and all the field works good, but after many researches I don't know how load correctly the array Estado define in TicketsApi.
This is the code that runs OK, thanks to Jason and the solution of the problem
<CollectionView
ItemsSource="{Binding ItemsSubasta}"
SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame BackgroundColor="#eee"
BorderColor="#ddd"
Padding="20">
<StackLayout x:DataType="model:TicketsApi">
<Label Text="{Binding Nombresolicitante, StringFormat='Nombres: {0:N}'}"
LineBreakMode="NoWrap"
FontSize="14" />
<Label Text="{Binding Apellidosolicitante, StringFormat='Apellidos: {0:N}'}"
LineBreakMode="NoWrap"
FontSize="14" />
<Label Text="{Binding CitaSolicitante, StringFormat='Fecha de consulta: {0}'}"
LineBreakMode="NoWrap"
FontSize="16" />
<Label Text="{Binding TiempoSolicitante, StringFormat='Tiempo: {0:N} minutos'}"
LineBreakMode="NoWrap"
FontSize="13" />
<Label Text="{Binding ValorSolicitante, StringFormat='Valor Consulta: {0:N} dólares (incluye IVA)'}"
LineBreakMode="NoWrap"
FontSize="13" />
<StackLayout BindableLayout.ItemsSource="{Binding Status}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Estado">
<Label Text="{Binding EstadoTransaccion }" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
I try though to show the correctly the fields inside "Estado" array which is inside TicketsApi model
英文:
I have a JSON response
{
"_id" : ObjectId("634b6be99237b35a9aa80dd5"),
"updatedAt" : ISODate("2022-10-16T02:27:44.766+0000"),
"createdAt" : ISODate("2022-10-16T02:26:49.276+0000"),
"firstName" : "Romulo",
"lastName" : "Calderon",
"email" : "romuloacd@gmail.com",
"phone" : "0962908538",
"description" : "Hoy u",
"user" : ObjectId("5aee09ef88b9ac4289109574"),
"appoinmentAt" : ISODate("2022-10-17T14:00:00.000+0000"),
"status" : [
{
"createdAt" : ISODate("2022-08-22T20:15:48.672+0000"),
"value" : "DEUDA",
"name" : "WITHOUT_PAYING"
},
{
"createdAt" : ISODate("2022-08-22T20:15:48.672+0000"),
"value" : "PAGADO",
"name" : "PAID_OUT"
}
],
"total" : 45.36,
"iva" : NumberInt(12),
"value" : 40.5,
"time" : NumberInt(30),
"__v" : NumberInt(0)
}
from an API call, I already show the most fields in collection without any problem, but I have inside the response another array defined in this model:
namespace App1.Models
{
public class TicketsApi
{
[JsonProperty("_id")]
public string Idtickets { get; set; }
[JsonProperty("user")]
public string Idusuario { get; set; }
[JsonProperty("firstName")]
public string Nombresolicitante { get; set; }
[JsonProperty("lastName")]
public string Apellidosolicitante { get; set; }
[JsonProperty("email")]
public string CorreoSolicitante { get; set; }
[JsonProperty("description")]
public string Motivoconsulta { get; set; }
[JsonProperty("phone")]
public string CelularSolicitante { get; set; }
[JsonProperty("value")]
public string ValorSolicitante { get; set; }
[JsonProperty("time")]
public string TiempoSolicitante { get; set; }
[JsonProperty("status")]
public Estado[] Status { get; set; }
[JsonProperty("appoinmentAt")]
public DateTime CitaSolicitante { get; set; }
[JsonProperty("createdAt")]
public DateTime FechaCreacion { get; set; }
}
public class Estado
{
[JsonProperty("value")]
public string EstadoPago { get; set; }
[JsonProperty("name")]
public string EstadoTransaccion { get; set; }
}
}
In the front I have this xaml code, and all the field works good, but after many researches I don't know how load correctly the array Estado define in TicketsAPi.
This is the code that runs OK, thanks to Jason and the solution of the problem
<CollectionView
ItemsSource="{Binding ItemsSubasta}"
SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame BackgroundColor="#eee"
BorderColor="#ddd"
Padding="20">
<StackLayout x:DataType="model:TicketsApi">
<Label Text="{Binding Nombresolicitante, StringFormat='Nombres: {0:N}'}"
LineBreakMode="NoWrap"
FontSize="14" />
<Label Text="{Binding Apellidosolicitante, StringFormat='Apellidos: {0:N}'}"
LineBreakMode="NoWrap"
FontSize="14" />
<Label Text="{Binding CitaSolicitante, StringFormat='Fecha de consulta: {0}'}"
LineBreakMode="NoWrap"
FontSize="16" />
<Label Text="{Binding TiempoSolicitante, StringFormat='Tiempo: {0:N} minutos'}"
LineBreakMode="NoWrap"
FontSize="13" />
<Label Text="{Binding ValorSolicitante, StringFormat='Valor Consulta: {0:N} dólares (incluye IVA)'}"
LineBreakMode="NoWrap"
FontSize="13" />
<StackLayout BindableLayout.ItemsSource="{Binding Status}"
>
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Estado" >
<Label Text="{Binding EstadoTransaccion }" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
I try though to show the correctly the fields inside "Estado" array which is inside TicketsApi model
答案1
得分: 0
您可以使用BindableLayout来显示一个项目集合,而不需要将其包装在CollectionView中。
请参考以下代码:
<CollectionView
ItemsSource="{Binding ItemsSubasta}"
SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame BackgroundColor="#eee"
BorderColor="#ddd"
Padding="20">
<StackLayout x:DataType="model:TicketsApi">
<Label Text="{Binding Nombresolicitante, StringFormat='Nombres: {0:N}'}"
LineBreakMode="NoWrap"
FontSize="14" />
<Label Text="{Binding Apellidosolicitante, StringFormat='Apellidos: {0:N}'}"
LineBreakMode="NoWrap"
FontSize="14" />
<Label Text="{Binding CitaSolicitante, StringFormat='Fecha de consulta: {0}'}"
LineBreakMode="NoWrap"
FontSize="16" />
<Label Text="{Binding TiempoSolicitante, StringFormat='Tiempo: {0:N} minutos'}"
LineBreakMode="NoWrap"
FontSize="13" />
<Label Text="{Binding ValorSolicitante, StringFormat='Valor Consulta: {0:N} dólares (incluye IVA)'}"
LineBreakMode="NoWrap"
FontSize="13" />
<!-- 在此添加代码 -->
<StackLayout BindableLayout.ItemsSource="{Binding Status}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding EstadoTransaccion}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
英文:
You can use BindableLayout to display a collection of items without wrapping it in CollectionView.
Please refer to the following code:
<CollectionView
ItemsSource="{Binding ItemsSubasta}"
SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame BackgroundColor="#eee"
BorderColor="#ddd"
Padding="20">
<StackLayout x:DataType="model:TicketsApi">
<Label Text="{Binding Nombresolicitante, StringFormat='Nombres: {0:N}'}"
LineBreakMode="NoWrap"
FontSize="14" />
<Label Text="{Binding Apellidosolicitante, StringFormat='Apellidos: {0:N}'}"
LineBreakMode="NoWrap"
FontSize="14" />
<Label Text="{Binding CitaSolicitante, StringFormat='Fecha de consulta: {0}'}"
LineBreakMode="NoWrap"
FontSize="16" />
<Label Text="{Binding TiempoSolicitante, StringFormat='Tiempo: {0:N} minutos'}"
LineBreakMode="NoWrap"
FontSize="13" />
<Label Text="{Binding ValorSolicitante, StringFormat='Valor Consulta: {0:N} dólares (incluye IVA)'}"
LineBreakMode="NoWrap"
FontSize="13" />
<!-- add code here -->
<StackLayout BindableLayout.ItemsSource="{Binding Status}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding EstadoTransaccion}"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论