Nativescript - Android 中的 raddataform 日期选择器

Nativescript - raddataform datepicker in Android

我在 raddataform 中使用日期选择器(Nativescript 使用 javascript) - 当我选择 2018 年 12 月 31 日时,日期选择器以以下格式显示日期 - Mon, 31.12 如何将其更改为更具可读性的格式?最好,MM/DD/YYYY 这仅在 android 中发生 - 在 ios 中它更具可读性。有什么建议吗?

<df:EntityProperty name="prdate" index="3" displayName="Date *" hintText="Enter Date *">
    <df:EntityProperty.editor>
        <df:PropertyEditor type="DatePicker">
            <df:PropertyEditor.propertyEditorStyle>
                <df:PropertyEditorStyle
                        labelHidden="true" labelWidth="0"
                        ios:labelFontName="Times New Roman" android:labelFontName="sans-serif-light"/>
            </df:PropertyEditor.propertyEditorStyle>
        </df:PropertyEditor>
    </df:EntityProperty.editor>
    <df:EntityProperty.validators>
        <df:NonEmptyValidator errorMessage="Please enter a date"/>
    </df:EntityProperty.validators>
</df:EntityProperty>

在 DatePicker 中更改格式仍然是 open feature request, but there is an workaround 已在同一期中展示的内容。

XML

<Page navigatedTo="navigated" loaded="onPageLoaded" xmlns:df="nativescript-pro-ui/dataform" xmlns="http://www.nativescript.org/tns.xsd">
    <GridLayout rows="100 *" columns="">
        <Label text="Test" textWrap="true" />


    <df:RadDataForm row="1"  id="myDataForm" source="{{ ticketOrder }}" propertyCommitted="dfPropertyCommitted">
        <df:RadDataForm.properties>
            <df:EntityProperty name="movie" displayName="Movie Name" index="0" converter="{{ $value }}" valuesProvider="{{ movieNames }}">
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="Picker" />
                </df:EntityProperty.editor>
            </df:EntityProperty>
            <df:EntityProperty name="date" index="1" >
                <df:EntityProperty.editor>
                    <df:PropertyEditor type="DatePicker" />
                </df:EntityProperty.editor>
            </df:EntityProperty>
            <!--......-->
    </df:RadDataForm>
    </GridLayout>

</Page>

TS

import viewModel = require("./../view-models/ticket-order-model");
import {RadDataForm, EntityProperty} from "nativescript-pro-ui/dataform";
import {isIOS, isAndroid} from "platform";
import {Page} from "ui/page";
declare var NSDateFormatter:any;
declare var java:any;
export function onPageLoaded(args) {
    var page = args.object;
    page.bindingContext = new viewModel.TicketViewModel();
}

export function dfPropertyCommitted(args) {
    //console.log("dfPropertyCommitted");
    var text = "LastEvent: " + args.propertyName + " property committed";
    //console.log(text);
}



export function navigated(args){
    console.log("navigatedTo");
    var page:Page = <Page>args.object;
    console.log("page");
    console.log(page)
    let component:RadDataForm = <RadDataForm>page.getViewById("myDataForm");
    console.log("component");
    console.log(component);
    let entity:EntityProperty = component.getPropertyByName("date");
    console.log("entity");
    console.log(entity);
    console.log("editor")
    if(isIOS){
        console.log(entity.editor.ios);
        var dateFormatter = NSDateFormatter.alloc().init();
        dateFormatter.dateFormat = "MM-yyyy-dd";
        entity.editor.ios.dateFormatter = dateFormatter;
    }else{
        var simpleDateFormat = new java.text.SimpleDateFormat("dd-MM-yyyy", java.util.Locale.US);
        entity.editor.android.setDateFormat(simpleDateFormat);
    }
}