簡體   English   中英

將視圖與Ember.js中的表單相關聯

[英]Associating a view with a form in Ember.js

我有幾個領域的表格。 當用戶單擊其中一個字段時,表單側面的div會填充有關該字段以及如何最好地填寫該字段的信息。 這個信息div實際上是一個視圖,我通過為每個字段分配一個tip屬性來用幫助文本填充它。 代碼如下:

# form field
Em.TextField valueBinding="name" tip="Put the <strong>name</strong> of your organization here."

# views
# Tip Box
Whistlr.TipBoxView = Em.View.extend
  templateName: 'tipBox'
  classNames: ['ember-tip-box']
  content: ""

  actions:

    setContent: (content) ->
      @set 'content', content

# Text field
Em.TextField.reopen
  tip: ''

  click: ->
    Ember.View.views[$(".ember-form-info-box").attr('id')].set 'content', @tip

# template
== view.content

這足夠好用,但是其中一部分確實讓我感到困擾。 具體來說,為了找到提示框視圖,我像這樣搜索它: Ember.View.views[$(".ember-form-info-box").attr('id')] 只要我只有一個帶有單個提示視圖的表單,此方法就可以工作,但是如果我有多個表單,它將失效。 目前這不是問題,但將來可能會出現問題。 它也感覺很hack。

有沒有更直接的方法將視圖與特定表單相關聯?

這似乎是一種過於復雜的方法。 為什么不使用jQuery TooltipsterCSS Tooltips之類的東西呢?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM