我正在使用raddataform中的datepicker(使用javaScript的nativescript) - 当我选择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中更改格式仍然是一个开放的功能请求,但是在同一问题中已经显示了一个解决方法。
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);
}
}