[英]How to Get “_id” field value from kinvey.com
I been using kinvey.com, and every time I try to get Manga._id
it returns null. 我一直在使用kinvey.com,每次尝试获取
Manga._id
它都会返回null。 Can you help me figure out why? 你能帮我弄清楚为什么吗?
TManga = class
strict private
FSite,
FManga,
FID: String;
published
property Site : string read FSite write FSite;
property Manga : string read FManga write FManga;
property _id : string read FID write FID;
/////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////// /////////////////////////
var
Mangas: TBackendObjectList<TManga>;
Manga : TManga;
QueryStr: TArray<string>;
i: Integer;
begin
with xQuery do
begin
Execute;
Mangas := TBackendObjectList<TManga>.Create;
QueryStr := TArray<string>.Create('');
xStorage.Storage.QueryObjects<TManga>('xxxx' ,QueryStr ,Mangas);
with xListBox do
begin
Items.BeginUpdate;
try
Items.Clear;
for I := 0 to Mangas.Count -1 do
begin
Manga := Mangas.Items[I];
items.add(Manga.Site + ' - ' + Manga._id) // Manga._id this is everytime null
end;
finally
Items.EndUpdate;
end;
end;
end;
http://i.hizliresim.com/M94QPN.png http://i.hizliresim.com/M94QPN.png
您是否尝试在QueryStr的数组元素之一中使用值“ fields = _id”?
Your column _id is always null because the Kinvey API doesn't get the _id column as a simple column but as the object ID of the record. 您的列_id始终为null,因为Kinvey API不会将_id列作为简单列而是作为记录的对象ID。 In order to get the object ID of your Manga record, you must to add a variable like this:
为了获取您的漫画记录的对象ID,您必须添加如下变量:
oEntity: TBackendEntityValue;
So right under this line in the "for" statement: 因此,在“ for”语句的这一行下:
Manga := Mangas.Items[I];
You may add these two new lines: 您可以添加以下两行:
oEntity := FBackendList.EntityValues[Manga]; // Gets the Kinvey object
Manga._id := oEntity.ObjectID; // Sets the _id property of the current TManga instance
One important thing you may take in mind is when you will add new records in your Kinvey collection. 您可能要记住的一件事是何时将新记录添加到Kinvey集合中。 You don't have to write in the _id property of your new TManga item before you create your new record.
创建新记录之前,您不必在新TManga项的_id属性中进行编写。 However you will need to get it from Kinvey right after you insert the new record.
但是,插入新记录后,您需要立即从Kinvey获取它。 This code was adapted from the Embarcadero's ToDo sample:
这段代码改编自Embarcadero的ToDo示例:
procedure TDataModule1.AddBackendItem(const AItem: TManga);
var
oEntity: TBackendEntityValue;
begin
// After the execution of this command the new record will be inserted in Kinvey, and the variable oEntity will get the respective object ID
BackendStorage1.Storage.CreateObject<TManga>(
TMangaNames.BackendClassname, AItem, oEntity);
AItem._id := oEntity.ObjectID; // Updates the property _id of the current instance of TManga
FBackendList.Add(AItem, oEntity);
end;
I hope it can help you! 希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.