1

我一直在使用 kinvey.com,每次尝试获取Manga._id它时都返回 null。你能帮我弄清楚为什么吗?

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

4

2 回答 2

0

您是否尝试在 QueryStr 的数组元素之一中使用值“fields=_id”?

于 2014-09-17T19:10:49.957 回答
0

您的 _id 列始终为空,因为 Kinvey API 不会将 _id 列作为简单列,而是将其作为记录的对象 ID。为了获取您的漫画记录的对象 ID,您必须添加如下变量:

  oEntity: TBackendEntityValue;

所以就在“for”语句的这一行下面:

  Manga := Mangas.Items[I];

您可以添加以下两个新行:

oEntity := FBackendList.EntityValues[Manga]; // Gets the Kinvey object
Manga._id := oEntity.ObjectID; // Sets the _id property of the current TManga instance

您可能要记住的一件重要事情是何时在您的 Kinvey 收藏中添加新记录。您不必在创建新记录之前写入新 TManga 项目的 _id 属性。但是,您需要在插入新记录后立即从 Kinvey 获取它。此代码改编自 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;

我希望它可以帮助你!

于 2015-04-01T07:11:20.070 回答