简体   繁体   English

微信小程序从ts发送object到wxs文件

[英]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:我正在使用 typescript 创建一个微信小程序,我有一个带有以下数据的人员类型 class:

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

Create Person object:创建人 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:在 wxml 中显示它时,我正在执行以下操作:

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

The dob property shows it as [object Object] dob属性显示为[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.我在 wxs 文件中创建了一个方法来转换dob属性并通过调用 Date object 的toDateString方法将其显示为字符串,但它给了我以下错误: dob.toDateString() is not a function ,如果我从.ts文件调用此方法可以正常工作,但是当我从 wxs 文件调用它时会出错。

The javascript environment and wxs environment of view is divided.I guess you may try to require the wxs file in wxml like this:视图的javascript环境和wxs环境是分的。我猜你可以尝试像这样要求wxml中的wxs文件:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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