1
    Ext.define("Datetimepicker.view.Main", {
               extend: 'Ext.form.Panel',
               requires: [
                                'Ext.TitleBar',
                                'Ext.field.DatePicker',
                                 'Ext.Spacer',
                                 'Ext.Picker'
                             ],
               config: {
                            fullscreen:'true',
                            title:'DatatimePicker',
                            items: [
                               {
                                   xtype:'fieldset',
                                        items:[
                                           {
                                              xtype:'datepickerfield',
                                              label:'Birthday',
                                              picker:{
                                                 yearFrom:1980,
                                                  yearTo:2015
                                               },
                                             name:'birthday',
                                             value:new Date()
                                         },
                                          {
                                            xtype:'textfield',
                                             label:'Time',
                                             value:''
                                           //In this textfield i want to display the time picker value
                                            }
                                        }
                                    ]
                                    },
                                 {

items:[
{
xtype:'spacer'
},
{
text: 'setValue',
handler: function() {
var datePickerField = Ext.ComponentQuery.query('datepickerfield')[0];
var randomNumber = function(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
};
datePickerField.setValue({
month: randomNumber(0, 11),
day : randomNumber(0, 28),
year : randomNumber(1980, 2015)
});
}
},
{ xtype:'spacer'}
]
}
]
}
});

上記のコードを使用して、最初のテキスト フィールドに正常に表示される datepicker の値を取得しています。同じように、その datepicker の値を別のテキスト フィールドに表示したいと考えています。誰でもこれを行うのを手伝ってもらえますか...事前に感謝します

4

1 に答える 1

1

textfield値が変更されるたびにの値を設定することでそれを行うことができるpicker'sので、ここに解決策があります:

 items: [
            {
                xtype: 'datepickerfield',
                label: 'Birthday',
                name: 'birthday',
                value: new Date(),
                listeners: {
                    change: function(picker, value) {
                        // This function use to prepend 0 to the month which less than October
                        function minTwoDigits(n) {
                            return (n < 10 ? '0' : '') + n;
                        }
                        var date = value.getDate(), // Get date's value
                            month = value.getMonth(); // Get month's value
                        month += 1; // Increase the number of month by 1 since the index started with 0
                        var formatMonth = minTwoDigits(month),
                            year = value.getFullYear(), // Get year's value
                            formatDate = formatMonth.concat("/",date,"/",year); // Concatenate string
                        Ext.ComponentQuery.query('#textfield')[0].setValue(formatDate); // Set the value of the textfield with itemID equal to textfield
                    }
                }
            },
            {
                xtype:'textfield',
                label:'time',
                itemId: 'textfield',
                value:''

            }
        ]

わからないことがあれば、遠慮なく聞いてください。それが役に立てば幸い :)

于 2013-01-23T12:18:23.827 に答える