2016-12-09 1 views
1

items의 배열이있다 :datetime을 설정하는 방법 extjs textfield의 값은 무엇입니까?

나는이 텍스트 필드에 날짜 시간 값을 설정해야합니다
items: [{ 
    fieldLabel: 'Username:', 
    id: 'usernameID', 
    readOnly: true, 
    value: user.username, 
    name: "username" 
}] 

: 일로부터

Ext.getCmp('usernameID').setValue(Fromdate); 

에서 내가 날짜의 가치를 얻을. 하지만 내가 설정하는 동안 :

Uncaught TypeError: Cannot read property 'setValue' of undefined

+0

시도는 항목 ID '' '대신에 ID의 usernameID'''usernameID'' 또는'Ext.getCmp ('[NAME = 자명])' – Zoran

+0

우선적 대신 사용하여 DateField 텍스트 필드 xtype : datefield, value : new Date(). http://docs.sencha.com/extjs/5.1.0/api/Ext.form.field.Date.html을 살펴보십시오. – josei

답변

1

항목에 xtype이 정의되어 있지 않습니다. 항목에 기본 xtype을 사용하고 있습니까? 텍스트 필드 또는 아무것도 렌더링 된 있습니까?

이 코드는 작동 : 경우

items: [{ 
    xtype: 'textfield', 
    id: 'myCustomId', 
    fieldLabel: 'Label', 
    name: 'username', 
    value: 'something', 
    readOnly: true 
}, { 
    xtype: 'button', 
    handler: function (button, e) { 
     var cmp = Ext.getCmp('myCustomId'); 
     cmp.setValue(Ext.Date.format(new Date(), 'Y-m-d')) 
    }, 
    text: 'Set the value' 
}] 

체크 아웃 바이올린 https://fiddle.sencha.com/#view/editor&fiddle/1m7f

이 당신이 코드의 많은 부분을 게시 도움이되지 않습니다.

0

먼저 xtype 속성을 사용하여 개체 유형을 정의하십시오. 그런 다음 date을 설정해야합니다. 이 예에서는 ExtJSdatepicker을 사용하여 날짜를 가져 왔지만 new Date()을 사용할 수도 있습니다.

날짜를 얻은 후에는 format 함수로 서식을 지정한 다음이 서식이 지정된 값으로 set 개체를 서식 지정해야합니다. 이 예제에서는 Y-d-m (년, 월 및 일)과 d-m-Y (일, 월 및 연도)의 두 가지 형식을 사용했습니다. 형식 액세스에 대한 자세한 내용은 this link을 참조하십시오.

다른 버전의 ExtJS에서 액세스하려면 this fiddle으로 테스트하십시오.

Ext.create('Ext.window.Window', { 
 
    title: 'Set Date', 
 
    closable: false, 
 
    width: 500, 
 
    layout: 'vbox', 
 
    bodyStyle: 'padding: 5px;', 
 
    items: [{xtype: 'container', 
 
      layout: { 
 
       type: 'hbox', 
 
       align: 'stretch' 
 
      }, 
 
      items: [{ 
 
       xtype: 'datepicker', 
 
       minDate: new Date(), 
 
       bodyStyle: 'padding-left: 50px;', 
 
       handler: function(picker, date) { 
 
        Ext.getCmp('txtDate1').setValue(Ext.Date.format(date, 'Y-m-d')); 
 
        Ext.getCmp('txtDate2').setValue(Ext.Date.format(date, 'd-m-Y')); 
 
       } 
 
      }, { 
 
       xtype: 'container', 
 
        layout: { 
 
         type: 'vbox', 
 
         align: 'stretch' 
 
        }, 
 
        items: [{ 
 
         xtype: 'textfield', 
 
         fieldLabel: 'Date 1:', 
 
         labelAlign: 'right', 
 
         id: 'txtDate1', 
 
         width: 200 
 
        }, { 
 
         xtype: 'textfield', 
 
         fieldLabel: 'Date 2:', 
 
         labelAlign: 'right', 
 
         id: 'txtDate2', 
 
         width: 200 
 
        }] 
 
      }] 
 
     }] 
 
}).show();
<script src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all.js"></script> 
 
<link type="text/css" rel="stylesheet" href="http://cdn.sencha.com/ext/gpl/4.2.0/resources/css/ext-all.css")/>

관련 문제