无法访问分析查询列表项
本文关键字:查询 列表 访问 | 更新日期: 2023-09-27 18:22:15
我正在使用Unity和Parse开发一个应用程序。该应用程序拍摄一张照片,上传到Parse,然后第二个功能应该检索所有上传的照片并显示相关数据。
我的问题是:
我正在运行一个Parse查询,从Parse中获取所有当前上传的项目,并通过objectId
将它们添加到列表中。我可以在Unity的Inspector中看到objectId
正在添加到列表中,但查询一结束,列表项就返回null。
理想情况下,我的意图是为列表中的每个项目创建一个新的Unity UI对象,并用从Parse检索到的数据填充每个项目中的文本字段。
以下是我目前正在使用的代码:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Parse;
public class RetrieveAllObjects : MonoBehaviour
{
public RectTransform InfoCell;
public float Vec3x;
public float Vec3y;
public List<string>AllObjectIds = new List<string> ();
string objectId;
DateTime? createdAt;
IEnumerable<ParseObject> results;
// Use this for initialization
void Start ()
{
var query = ParseObject.GetQuery ("Snapshot")
.OrderByDescending("createdAt");
query.FindAsync ().ContinueWith (u =>
{
results = u.Result;
foreach (var result in results) {
objectId = result.ObjectId;
createdAt = result.CreatedAt;
print ("Object ID: " + objectId + "'n" + "Date Created: " + createdAt);
AllObjectIds.Add (objectId);
}
return AllObjectIds;
});
foreach (string id in AllObjectIds) {
CreateInfoCell ();
}
}
void CreateInfoCell ()
{
RectTransform newCell = Instantiate (InfoCell);
newCell.transform.SetParent (this.gameObject.transform);
newCell.transform.localScale = new Vector3 (1, 1, 1);
Vec3y = Vec3y - 50;
}
// Update is called once per frame
void Update ()
{
}
}
我能够通过使用IE分子来解决这个问题。
以下代码:
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Parse;
public class RetrieveAllObjects : MonoBehaviour
{
public RectTransform InfoCell;
public Text IdText;
public Text DateText;
public float Vec3x;
public float Vec3y;
public List<string>AllObjectIds = new List<string> ();
public List<string>CreatedAtDates = new List<string> ();
public GameObject AnchorPos;
int num;
string objectId;
DateTime? createdAt;
IEnumerable<ParseObject> results;
// Use this for initialization
void Start ()
{
var query = ParseObject.GetQuery ("Snapshot")
.OrderByDescending("createdAt");
query.FindAsync ().ContinueWith (u =>
{
results = u.Result;
foreach (var result in results) {
objectId = result.ObjectId;
createdAt = result.CreatedAt;
// print ("Object ID: " + objectId + "'n" + "Date Created: " + createdAt);
AllObjectIds.Add (objectId);
CreatedAtDates.Add (createdAt.ToString());
}
foreach (string id in AllObjectIds) {
// CreateInfoCell ();
// print (id);
}
foreach (string date in CreatedAtDates) {
// CreateInfoCell ();
// print (date);
}
return AllObjectIds;
return CreatedAtDates;
});
StartCoroutine (UpdateUI ());
}
IEnumerator UpdateUI () {
yield return new WaitForSeconds(1);
var query = ParseObject.GetQuery ("Snapshot");
Task task = query.FindAsync ();
while(!task.IsCompleted) yield return null;
// Do all your continue with stuff here
foreach (string id in AllObjectIds) {
CreateInfoCell (id);
}
AnchorPos.SetActive (false);
}
void CreateInfoCell (string id)
{
// print ("CELL CREATED'n");
RectTransform newCell = Instantiate (InfoCell);
newCell.name = id + " - " + CreatedAtDates[num];
GameObject PutIdText = GameObject.Find(newCell.name + "/ObjectIdText");
PutIdText.GetComponent<Text> ().text = id;
GameObject PutDateText = GameObject.Find(newCell.name + "/DateCreatedText");
PutDateText.GetComponent<Text> ().text = CreatedAtDates[num];
StartCoroutine (DisplayThumbnail(newCell, id));
// IdText.text = id;
// DateText.text = CreatedAtDates[num];
num++;
newCell.transform.SetParent (this.gameObject.transform);
newCell.transform.localScale = new Vector3 (1, 1, 1);
newCell.transform.position = new Vector3 (AnchorPos.transform.position.x, AnchorPos.transform.position.y - Vec3y, AnchorPos.transform.position.z);
Vec3y = Vec3y + 100;
}