如何从列表中的Parse.com获取数据并将其应用于listview?

Yen*_*the 3 c# parse-platform xamarin

我对Parse.com很新,似乎无法获取数据.我尝试了一个异步方法,它做了一个foreach,但似乎从来没有工作,所以我尝试了一个ParseQuery但是也没有用.例如:

ParseQuery<ParseObject> query = ParseObject.GetQuery("Horse");
string name = query.Get<string>("Name");
Debug.WriteLine("Horse: " + name);
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想从模型中获取所有记录Horse,然后循环遍历它以填充列表视图.我现在有一个硬编码的样本,但由于我甚至没有从列表中的表中获取所有记录,我不知道如何继续.

var listView = new ListView
        {
            RowHeight = 40
        };
        listView.ItemsSource = new string[]
            {
            //This should be filled up with the field 'Name' from the model 'Horse' dynamically..
            "Buy pears",
            "Buy oranges",
            "Buy mangos",
            "Buy apples",
            "Buy bananas"
            };
        Content = new StackLayout
        {
            VerticalOptions = LayoutOptions.FillAndExpand,
            Children = { listView }
        };
Run Code Online (Sandbox Code Playgroud)

请问有人帮我吗?我按照https://parse.com/docs/dotnet_guide#objects-retrieving的指南进行操作,但这些选项似乎不起作用.

更新: 到目前为止,由于har07的答案,我可以获取所有数据.现在,当我想要填充ListView时出现错误:

public async void getHorsesFromDb()
    {
        ParseQuery<ParseObject> query = ParseObject.GetQuery("Horse");
        IEnumerable<ParseObject> horses = await query.FindAsync();

        var listView = new ListView();
        List<string> horseList = null;

        foreach (ParseObject horse in horses)
        {
            string name = horse.Get<string>("Name");
            horseList.Add(name);
            Debug.WriteLine("Horse: " + name);
        }

        listView.ItemsSource = horseList;

        // Using ItemTapped
        listView.ItemTapped += async (sender, e) => {
            await DisplayAlert("Tapped", e.Item + " row was tapped", "OK");
            Debug.WriteLine("Tapped: " + e.Item);
            ((ListView)sender).SelectedItem = null; // de-select the row
        };
    }
Run Code Online (Sandbox Code Playgroud)

我的屏幕出错:

The current stack frame was not found in a loaded module. Source cannot be shown for this location.
>   0x21 in System.Diagnostics.Debugger.Mono_UnhandledException_internal    C#
Run Code Online (Sandbox Code Playgroud)

har*_*r07 5

您所关注的链接显示了如何ParseObject通过将特定objectId(xWMyZ4YEGZ在该示例中为哪个值)传递给查询来获取单行数据().

另一方面,要从表中获取多行,请遵循相同的查询部分.获取所有行甚至应该更简单(到目前为止不需要编写任何LINQ):

ParseQuery<ParseObject> query = ParseObject.GetQuery("Horse");
IEnumerable<ParseObject> horses = await query.FindAsync();
foreach (ParseObject horse in horses)
{
    string name = horse.Get<string>("Name");
    Debug.WriteLine("Horse: " + name);
}
Run Code Online (Sandbox Code Playgroud)