【问题标题】:Backgrid.SelectCell.extend option value must be a number?Backgrid.SelectCell.extend 选项值必须是数字吗?
【发布时间】:2019-10-22 07:16:39
【问题描述】:

嗨,伙计们。如何使用 Backgrid.SelectCell.extend 将 SelectCell 的选项值从字符串转换为数字?我需要选择年份列表,例如 [2019,2019]、[2018,2018]、[2017,2017]。

【问题讨论】:

    标签: javascript backbone.js backgrid


    【解决方案1】:

    我找到了解决办法。首先创建一个新的 javascript 变量(我命名为 SelectNumber)

    `

    var SelectNumber = Backgrid.SelectCell.extend({
      // any options specific to `select2` goes here
      selectOptions: {
        // default is false because Backgrid will save the cells value
        // and exit edit mode on enter
        openOnEnter: false
      },
      //optionValues: godine,
      // since the value obtained from the underlying `select` element will always be a string,
      // youll need to provide a `toRaw` formatting method to convert the string back to a
      // type suitable for your model, which is an integer in this case.
      formatter: _.extend({}, Backgrid.SelectFormatter.prototype, {
    toRaw: function (formattedValue, model) {
        return parseInt(formattedValue);
      }
      })
    });
    

    ` 然后添加一个 nev 变量 '

    var numbers=
    [   
     [2019,2019],[2018,2018],[2017,2017],[2016,2016]
    ,[2015,2015],[2014,2014],[2013,2013],[2012,2012]
    ,[2011,2011],[2010,2010],[2009,2009]   
    ] ;
    

    '

    并将列添加到网格

    '{ 名称:“号码”, 标签:“数字”, 单元格:SelectNumber.extend({optionValues: numbers})

    },'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 1970-01-01
      • 2022-06-24
      • 2022-10-21
      • 1970-01-01
      • 2011-02-08
      • 1970-01-01
      相关资源
      最近更新 更多