【问题标题】:Angular UI-Bootstrap Typeahead with object literal structure具有对象文字结构的 Angular UI-Bootstrap Typeahead
【发布时间】:2015-06-09 18:51:02
【问题描述】:

是否可以将 Angular UI-Bootstrap Typeahead 与以下数据一起使用?此数据是 wordpress 分类的表示,格式为 term_id : term_name

$scope.domainFields = {
    "304": "Administration et secr\u00e9tariat",
    "305": "Arts, m\u00e9dias et divertissement",
    "306": "Assurance",
    "307": "Comptabilit\u00e9 et finance"
    //...
};

查看:

我正在使用 Angular-xeditable typeahead,它实现了 Angular-ui typeahead。

currentUser.field 包含当前的term_id,如何在e-typeahead 中循环遍历domainFields 对象并显示与term_id 关联的当前term_name?

<a href="#"
   editable-text="currentUser.field"
   e-typeahead="
   term_id as term_name for field in domainFields
   | filter:$viewValue 
   | limitTo:8">
{{ domainFields[currentUser.field] || 'empty' }}
</a>

【问题讨论】:

    标签: angularjs angular-ui-bootstrap


    【解决方案1】:

    e-typeahead 中指定重复数组时,您需要在对象中使用 (key, value)

    标记

    <a href="#"
       editable-text="currentUser.field"
       e-typeahead="
       term_id as term_name for (term_id, term_name) in domainFields
       | filter:$viewValue 
       | limitTo:8">
    {{ domainFields[currentUser.field] || 'empty' }}
    </a>
    

    【讨论】:

    • 嗨,它给出了错误 Error: Expected typeahead specification in form of "modelValue (as label)? for itemcollection 中”,但在 domainFields | filter:$viewValue | limitTo:8 中获得了“term_id 作为 (term_id, term_name) 的 term_name”。
    • @ericsicons 我认为这个问题已经在这里解决了github.com/angular-ui/bootstrap/issues/3350
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    相关资源
    最近更新 更多