【问题标题】:Selected field is blank when fetches a Backbone collection with Backbone-forms使用 Backbone-forms 获取 Backbone 集合时,选定字段为空白
【发布时间】:2013-08-18 18:37:52
【问题描述】:

我使用Backbone-forms 填充模型。我有一个带有骨干集合的选择字段作为方案中的选项。当此集合为空时,backbone-forms 会进行一次提取,但 select 的 html 显示为空白。

当集合不为空时,总是将第一个选项作为值。

我想第一次,当集合为空时,它也会默认显示第一个值。

class foo extends Backbone.Model
  schema:
    tag:
     type: 'select'
     options: new App.Collections.Tags

【问题讨论】:

    标签: backbone.js backbone-forms


    【解决方案1】:

    看例子

    http://jsfiddle.net/evilcelery/dW2Qu/

    var user = new User({
        title: 'Mr',
        name: 'Sterling Archer',
        email: 'sterling@isis.com',
        birthday: new Date(1978, 6, 12),
        password: 'dangerzone',
        notes: [
            'Buy new turtleneck',
            'Call Woodhouse',
            'Buy booze'
        ]
    });
    

    这些是默认值。

    在你的情况下,你会使用类似于

    var options = new App.Collection.Tags;
    class foo extends Backbone.Model
      schema:
        tag:
         type: 'select'
         options: options
    for (first in options) break;
    var Foo = new foo({tag:first}); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 2011-11-25
      相关资源
      最近更新 更多