我正在使用raddataform中的日期选择器(使用JavaScript的本地脚本)-当我选择2018年12月31日时,日期选择器将以以下格式显示日期-31.12,星期一 如何将其更改为更具可读性的格式?最好是MM / DD / YYYY 这仅在android中发生-在ios中更易读。有什么建议吗?
-Xms
答案 0 :(得分:0)
DatePicker中的更改格式仍然是open feature request,但是在同一期中已经展示了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);
}
}