I solved it using mx.data.get(), but I was under the impression that it was deprecated.
I am also using a datasource connection, meaning it will fetch all objects, which I then need to fetch again using:
// @ts-ignore
function getMxObject(guid: string, callback: (obj: mendix.lib.MxObject) => void): void {
// @ts-ignore
mx.data.get({
guid,
callback,
error: (err: string) => {
console.error("Failed to retrieve object:", err);
}
});
}
So I need to fetch the objects several times, which will eat more bandwidth.
I am thinking the best way would be to pass all of the objects into the widget and be able to use them in there without having to do a separate get request.
The reason I have the @ts-ignores is because I can't for the life of me figure out where to get the types for the Client API. Does anybody have an idea?
The interfaces that doesn't exist are the mendix.lib.MxObject and the mx.data.get().
Thanks
Hi Pontus,
The intended mechanism to get data from Mendix Objects is using an Attribute Property linked to a datasource. The attribute property will provide a `get()` method that accepts the object reference and returns the value as an EditableValue:
function ExampleWidget(props) {
return(
<ul>
{props.datasourceProperty.items.map(i => <li>{props.attributeProperty.get(i).displayValue}</li>)}
</ul>
);
}
This has the benefit that your widget does not become tightly coupled to a specific Entity type. The user of your widget can then specify what attribute of a given entity is the "Title" attribute.
I hope this helps,
Arjo
Pontus, when you say a helper object, do you mean a non-persistable entity?
Also, can you share the version of StudioPro and the pluggable widget tools you are using?