将视图与 Ember.js 中的窗体相关联

Associating a view with a form in Ember.js

本文关键字:窗体 关联 js 视图 Ember      更新时间:2023-09-26

我有一个包含多个字段的表单。当用户单击其中一个字段时,表单一侧的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')] .只要我只有一个带有单个提示视图的表单,这就可以工作,但是如果我有多个表单,它会中断。这目前不是问题,但将来可能会出现问题。也感觉很笨拙。

是否有更直接的方法将视图与特定表单相关联?

这似乎是一种过于复杂的方法。为什么不使用jQuery Tooltipster或CSS Tooltips之类的东西呢?