diff --git a/sources/MVCFramework.Commons.pas b/sources/MVCFramework.Commons.pas index 3f312af1..7ad56582 100644 --- a/sources/MVCFramework.Commons.pas +++ b/sources/MVCFramework.Commons.pas @@ -35,6 +35,7 @@ interface System.SysUtils, System.SyncObjs, System.IOUtils, + System.RTTI, Data.DB, IdGlobal, IdCoderMIME, @@ -517,7 +518,7 @@ TMVCStringObjectDictionary = class procedure Add(const Name: string; Value: T); end; - TMVCViewDataObject = class(TObjectDictionary) + TMVCViewDataObject = class(TObjectDictionary) private { private declarations } protected diff --git a/sources/MVCFramework.View.Renderers.Mustache.pas b/sources/MVCFramework.View.Renderers.Mustache.pas index bcc8279b..380148cd 100644 --- a/sources/MVCFramework.View.Renderers.Mustache.pas +++ b/sources/MVCFramework.View.Renderers.Mustache.pas @@ -31,7 +31,8 @@ interface uses MVCFramework, System.SysUtils, System.Generics.Collections, - MVCFramework.Commons, System.IOUtils, System.Classes, Data.DB, SynMustache, SynCommons; + MVCFramework.Commons, System.IOUtils, System.RTTI, + System.Classes, Data.DB, SynMustache, SynCommons; type { This class implements the mustache view engine for server side views } @@ -204,8 +205,7 @@ procedure TMVCMustacheViewEngine.LoadPartials; procedure TMVCMustacheViewEngine.PrepareModels; var - lList: IMVCList; - DataObj: TPair; + DataObj: TPair; lDSPair: TPair; lSer: TMVCJsonDataObjectsSerializer; lJSONModel: TJsonObject; @@ -233,15 +233,16 @@ procedure TMVCMustacheViewEngine.PrepareModels; begin for DataObj in ViewModel do begin - lList := TDuckTypedList.Wrap(DataObj.Value); - if lList <> nil then - begin - lSer.ListToJsonArray(lList, lJSONModel.A[DataObj.Key], TMVCSerializationType.stProperties, nil); - end - else - begin - lSer.ObjectToJsonObject(DataObj.Value, lJSONModel.O[DataObj.Key], TMVCSerializationType.stProperties, nil); - end; + lSer.TValueToJSONObjectProperty(lJSONModel, DataObj.Key, DataObj.Value, TMVCSerializationType.stDefault, nil, nil); +// lList := TDuckTypedList.Wrap(DataObj.Value); +// if lList <> nil then +// begin +// lSer.ListToJsonArray(lList, lJSONModel.A[DataObj.Key], TMVCSerializationType.stProperties, nil); +// end +// else +// begin +// lSer.ObjectToJsonObject(DataObj.Value, lJSONModel.O[DataObj.Key], TMVCSerializationType.stProperties, nil); +// end; end; end; diff --git a/sources/MVCFramework.pas b/sources/MVCFramework.pas index ead29dc9..928ec004 100644 --- a/sources/MVCFramework.pas +++ b/sources/MVCFramework.pas @@ -780,9 +780,9 @@ TMVCController = class(TMVCRenderer) fPageHeaders: TArray; fPageFooters: TArray; function GetSession: TMVCWebSession; - function GetViewData(const aModelName: string): TObject; + function GetViewData(const aModelName: string): TValue; function GetViewDataset(const aDataSetName: string): TDataSet; - procedure SetViewData(const aModelName: string; const Value: TObject); + procedure SetViewData(const aModelName: string; const Value: TValue); procedure SetViewDataset(const aDataSetName: string; const Value: TDataSet); protected const CLIENTID_KEY = '__clientid'; @@ -863,7 +863,7 @@ TMVCController = class(TMVCRenderer) procedure PushDataSetToView(const aModelName: string; const ADataSet: TDataSet); deprecated 'Use "ViewDataSet"'; - property ViewData[const aModelName: string]: TObject read GetViewData write SetViewData; + property ViewData[const aModelName: string]: TValue read GetViewData write SetViewData; property ViewDataset[const aDataSetName: string]: TDataSet read GetViewDataset write SetViewDataset; @@ -3815,7 +3815,7 @@ class procedure TMVCRenderer.InternalRenderMVCResponse( end; -function TMVCController.GetViewData(const aModelName: string): TObject; +function TMVCController.GetViewData(const aModelName: string): TValue; begin if not FViewModel.TryGetValue(aModelName, Result) then Result := nil; @@ -4128,7 +4128,7 @@ procedure TMVCController.SetPagesCommonHeaders(const AViewNames: TArray) fPageHeaders := AViewNames; end; -procedure TMVCController.SetViewData(const aModelName: string; const Value: TObject); +procedure TMVCController.SetViewData(const aModelName: string; const Value: TValue); begin GetViewModel.Add(aModelName, Value); end;