Closed tsuga closed 1 month ago
@tsuga - This looks to be a bug. We are investigating and will create an item in our backlog. We'll provide updates here once available. Thanks!
@EsterBergen Thank you for picking this up. Is there any update?
@EsterBergen Is there any update?
HI @tsuga - We don't have an update to share at this moment and will let you know here when more details are available. Thanks for your patience!
@tsuga - Thanks again for reaching out, This is actually by design, @gergzk can provide any follow-up to questions you may have here.
@EsterBergen Thank you for the update, but I'm afraid I don't get it. If this is by design, how can I use PowerPoint.ShapeScopedCollection.toJSON
?
@tsuga - the intent of the toJSON implementation is to override the JSON.stringify behavior to avoid throwing. The objects (eg: ShapeScopedCollection) have circular references and other non-stringifiy'able content.
@gergzk Thank you for clarifying, but what you explained to me here does not align with what is written on the docs.
toJSON() Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original PowerPoint.ShapeScopedCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as PowerPoint.Interfaces.ShapeScopedCollectionData) that contains an "items" array with shallow copies of any loaded properties from the collection's items.
Your Environment
Expected behavior
toJSON
should return a js object with properties loaded.Current behavior
toJSON
returns an empty object even though a property (i.e.id
in the code below) is loaded.Steps to reproduce
function run() { PowerPoint.run(async (context) => { const shapes = context.presentation.getSelectedShapes(); shapes.load("items") await context.sync(); const items = shapes.items; items.forEach((shape) => shape.load('id')); await context.sync(); console.log(items[0].id); // 2 - the
id
property is loaded. console.log(JSON.stringify(items)); // expected: [{id: 2}] current: [{}] }); }