2015-04-12 74 views
0

我有這樣的代碼的變化值MeteorJS:輸入文本

product.jade

a#home(href="{{pathFor 'home'}}") Home 
input#qty.form-control(type="text", value="1", name="qty") 

product.coffee

Template['product'].events 
    'click #home': (e, template) -> 
     text = template.find("#qty") 
     ??? 
     return 

如何設置數量的值每次點擊時家中有5個?我試圖使用text.value(「5」),但發生錯誤

Uncaught TypeError: string is not a function.

任何想法?

+0

該文件稱爲'product.jade'但模板名稱是'header'?這很好,但我只想確定哪個模板包含哪些元素。 –

回答

0

試試這個:

Template.product.events 
    'click #home': -> 
    $('#qty').val 5 

請即ID應該永遠只能在頁面上出現一次的頭腦,所以template.find是不是真的有必要在這裏。

0

試試這個:

Template.product.events 
    'click #home': (e, template) -> 
    template.$('#qty').val 5 

或者這樣:

Template.product.events 
    'click #home': (e) -> 
    $(e.currentTarget).parent().find('#qty').val 5