Hi,
What is the best way to get Const/Enum value (declared in Core.Shared project) in abp/jquery ajax ?
I need to call an abp.service from js, and use a Const/Enum value in parameter
Thanks
7 Answer(s)
-
0
hi,
you can write the const/enum values in the page layout
<script type="text/javascript"> abp.enums.chatMessageReadState = {unread: @((int)ChatMessageReadState.Unread), read: @((int)ChatMessageReadState.Read)}; </script>
and in your JS file you can retrieve it:
var unreadEnumValue = abp.enums.chatMessageReadState.unread
I wrote the code on top my head. So it's just for guiding .
-
0
It's not possible
My code is :
<script type="text/javascript"> abp.enums.documentsTypeCodes = { cvTypeCode: @((int)BlobConsts.Documents.Cv.TypeCode), pieceIdTypeCode: @((int)BlobConsts.Documents.PieceIdentite.TypeCode), diplomeTypeCode: @((int)BlobConsts.Documents.Diplome.TypeCode), autresDocsTypeCode: @((int)BlobConsts.Documents.AutresDocuments.TypeCode), }; </script>
Error is
Uncaught TypeError: Cannot set property 'documentsTypeCodes' of undefined
-
0
because
abp.enums
is undefined! try<script type="text/javascript"> var abp = abp || {enums:{}}; abp.enums.documentsTypeCodes = { cvTypeCode: @((int)BlobConsts.Documents.Cv.TypeCode), pieceIdTypeCode: @((int)BlobConsts.Documents.PieceIdentite.TypeCode), diplomeTypeCode: @((int)BlobConsts.Documents.Diplome.TypeCode), autresDocsTypeCode: @((int)BlobConsts.Documents.AutresDocuments.TypeCode), }; </script>
-
0
Still not working.
Cannot set property 'documentsTypeCodes' of undefined
I found a workaround by using html attribute with this enum on my component ...
-
0
sorry my bad!
<script type="text/javascript"> abp.enums = { documentsTypeCodes : { cvTypeCode: @((int)BlobConsts.Documents.Cv.TypeCode), pieceIdTypeCode: @((int)BlobConsts.Documents.PieceIdentite.TypeCode), diplomeTypeCode: @((int)BlobConsts.Documents.Diplome.TypeCode), autresDocsTypeCode: @((int)BlobConsts.Documents.AutresDocuments.TypeCode) } } </script>
-
0
Is there anyway we can generate JSON object automatically from Enums? So that we won't have to edit JS code everytime we have a new value in Enums.
-
0