简体   繁体   中英

WeChat Miniprogram send object from ts to wxs file

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM