Nativescript RadDataForm:JS:绑定:设置RadDataForm <mydataform>的属性源时发生绑定错误

时间:2019-03-24 09:19:07

标签: android nativescript

我正在尝试使用原始脚本RadformData,但是当我绑定数据模型时,总是会出现此错误“ JS:绑定:设置RadDataForm的属性源时发生绑定错误” ,当我导航到Radformdata页面上,我通过更改package.json中的dataform版本尝试了很多事情,我也清理了平台,但是没有运气,请咨询

这是我的代码: event-page.xml

<Page loaded="onPageLoaded" xmlns:df="nativescript-ui-dataform" 
xmlns="http://www.nativescript.org/tns.xsd">
    <ActionBar title="Add Event" />
        <df:RadDataForm id="myDataForm" source="{{ calEvent }}">
            <df:RadDataForm.properties>
            <df:EntityProperty name="title" hintText="Title" index="0">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="Text"></df:PropertyEditor>
                </df:EntityProperty.editor>
            </df:EntityProperty>
            <df:EntityProperty name="description" hintText="Description" index="1">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="Text"></df:PropertyEditor>
                </df:EntityProperty.editor>
            </df:EntityProperty>

            <df:EntityProperty name="stringDate" hintText="select date" index="2">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="DatePicker"></df:PropertyEditor>
                </df:EntityProperty.editor>
            </df:EntityProperty>
            <df:EntityProperty name="dateDate" hintText="select date" index="3">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="DatePicker"></df:PropertyEditor>
                </df:EntityProperty.editor>
            </df:EntityProperty>
            <df:EntityProperty name="timestampDate" hintText="select date" index="4" converter="{{ timestampConverter }}">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="DatePicker"></df:PropertyEditor>
                </df:EntityProperty.editor>
            </df:EntityProperty>
            <df:EntityProperty name="stringTime" hintText="select time" index="5">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="TimePicker"></df:PropertyEditor>
                </df:EntityProperty.editor>
            </df:EntityProperty>
            <df:EntityProperty name="dateTime" hintText="select time" index="6">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="TimePicker"></df:PropertyEditor>
                </df:EntityProperty.editor>
            </df:EntityProperty>
            <df:EntityProperty name="timestampTime" hintText="select time" index="7" converter="{{ timestampConverter }}">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="TimePicker"></df:PropertyEditor>
                </df:EntityProperty.editor>
            </df:EntityProperty>
        </df:RadDataForm.properties>
        </df:RadDataForm>
</Page>

event-page.ts

import { EventViewModel } from "./event-view-model";
import { Page } from "tns-core-modules/ui/page/page";

export function onPageLoaded(args) {
    const page = <Page>args.object;
    var eventModel = new EventViewModel();
    page.bindingContext = eventModel;
}

event-view-model.ts

import { Observable } from "tns-core-modules/data/observable";
import { PropertyConverter } from "nativescript-ui-dataform";

export class EventViewModel extends Observable {

    private _event: CalEvent;

    constructor() {
        super();
        this.set("timestampConverter", new TimestampConverter());
        this.onSetDefaults();
    }

    public onSetDefaults() {
        const stringDate = "1999-08-11";
        const dateDate = new Date();
        const timestampDate = (new Date()).getTime();   
        const stringTime = "11:04";
        const dateTime = new Date(1);
        const timestampTime = (new Date()).getTime();
        this._event =  new CalEvent("First Event","Desc",stringDate, dateDate, timestampDate, stringTime, dateTime, timestampTime);
    }

    get calEvent(): CalEvent{
        return this._event;
    }
}

export class TimestampConverter implements PropertyConverter {

    public convertFrom(timestamp: number) {
        const date = timestamp ? new Date(timestamp) : null;
        const result = date === null ? null : date.toJSON();
        return result;
    }

    public convertTo(dateString: string) {
        const date = new Date(dateString);
        const result = date ? date.getTime() : 0;
        return result;
    }
}

export class CalEvent {
    public title: string;
    public description: string;
    public stringDate: string;
    public dateDate: Date;
    public timestampDate: number;
    public stringTime: string;
    public dateTime: Date;
    public timestampTime: number;


    constructor(title: string, desc: string, stringDate: string, dateDate: Date, timestampDate: number, stringTime: string, dateTime: Date, timestampTime: number) {
        this.title = title;
        this.description = desc;
        this.stringDate = stringDate;
        this.dateDate = dateDate;
        this.timestampDate = timestampDate;
        this.stringTime = stringTime;
        this.dateTime = dateTime;
        this.timestampTime = timestampTime;
    }
}

0 个答案:

没有答案