2017-05-04 56 views
1

我使用emberjs,我有一個小問題,如何使用emberjs handlebars獲取input type =「date」的值?

看到我有這個日期輸入字段,我想每一個客戶端更改日期

雖然你不及時觸發一個

行動這裏不需要它是處理動作的方法

getDate(){ 
    console.log("HELLO WORLD!") 
} 

/* {{input value=model.date class="ux-serviceform-body-name w-input" type="date}} */ 

我怎麼能包括一個行動處理程序在這個領域?

我已經嘗試過

"on-change='getDate'"}} 
"on='change' action='getDate'"}} 
"action='getDate'"}} 

無上述解決方案做了工作

感謝

+0

你的'''在你的hbs文件中缺少''type =「date」' –

+0

如果這不是問題,只需發佈​​一個解釋你的問題的小問題,因爲我確定它應該按照預期的方式工作' –

+0

https://ember-twiddle.com/ –

回答

2

只需使用change=(action "getDate")。這會給你發起的事件。

如果您只想獲得新值,請使用change=(action "myaction" value='target.value')

這就是:

{{input type="date" change=(action "myaction" value='target.value')}} 

你可以看一下this api doc

+0

我從來沒有料到type =「date」會提供如此精彩的日期選擇器!你能解釋一下UI是從哪裏來的嗎?是否支持日期和時間? 。 – kumkanillam

+1

它來自[html5'input type = date'](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date)。實際上,Firefox並不支持它。你可以檢查[瀏覽器](https://caniuse.com/#search=input%20type%3D%22date%22)。使用一些[html 5 polyfills](https://www.google.com.tr/search?q = html5 + input + date + polyfill)可以幫助。[此鏈接](https://developer.mozilla.org/en-US/docs/Web/HTML/Elem ent/input/date#Handling_browser_support)還提供了一個polyfill。但是我們通常在我們的項目中使用[ember-pikaday](https://github.com/edgycircle/ember-pikaday)。 – ykaragol

+1

你也可以使用'input type =「datetime-local」'作爲日期和時間。 [資源](https://html.spec.whatwg.org/multipage/forms.html#local-date-and-time-state-(type = datetime-local)) – ykaragol

相關問題