【问题标题】:Ember's select options are wrong when using RESTAdapter使用 RESTAdapter 时 Ember 的选择选项错误
【发布时间】:2013-04-21 15:21:02
【问题描述】:

我使用 RESTAdapter 模型在 Ember 的选择视图中填充选项。

contentBinding 映射到控制器中的 a 属性,这里我使用 this.set('myProperty', model.find(someQuery))。

具有 1 个结果的 model.find(someQuery) 效果很好,但是具有许多结果的 model.find(someQuery) 效果很奇怪。结果中的最后一个对象显示的次数与结果的长度一样多。

{{查看 Ember.Select contentBinding="myProperty" optionValuePath="content.id" optionLabelPath="content.name" selectionBinding="selectedResult" 提示=""}}

【问题讨论】:

    标签: view ember.js ember-data


    【解决方案1】:

    有趣。乍一看,您问题中包含的代码看起来不错。调试:

    1) 检查以确保查询结果符合您的预期。

    content = model.find(someQuery); //with many results
    // wait for results...
    console.log(content.getEach('id')); //expect array of ids
    console.log(content.getEach('name')); //expect array of names
    

    2) 检查 myProperty 的内容 - 来自模板:

    {{#each myProperty}}
      <pre>{{id}}.{{name}}</pre>
    {{/each}}
    

    期望模板为每个选项输出 id/name。

    【讨论】:

    • 谢谢迈克。数组的所有对象的 id 都是相同的(doh !!)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 1970-01-01
    相关资源
    最近更新 更多