WeChat Miniprogram send object from ts to wxs file

101 Views Asked by At

I am creating a WeChat miniprogram using typescript, I have a Person type class with the following data:

export class Person {
   dob: Date;
   firstName: String;
   lastName: String;
}

Create Person object:

let person = new Person ();
person.dob = new Date ();
person.fisrtName = "XXX";
person.lastName = "YYY";

this.setData ({
person: person
})

At the time of displaying it in the wxml I am doing the following:

<view> {{person.firstName}} </view>
<view> {{person.lastName}} </view>
<view> {{person.dob}} </view>

The dob property shows it as [object Object]

I have created a method in a wxs file to transform the dob property and display it as a string by calling the toDateString method of the Date object, but it gives me the following error: dob.toDateString() is not a function, if I call this method from the .ts file it works fine but when I call it from the wxs file it gives an error.

1

There are 1 best solutions below

1
On

The javascript environment and wxs environment of view is divided.I guess you may try to require the wxs file in wxml like this: