【问题标题】:knockout- x-editable not loading the select list淘汰赛-x-editable 未加载选择列表
【发布时间】:2014-07-04 15:05:37
【问题描述】:

我是 x-editable 和淘汰赛的新手,任何人都可以帮助我为什么下面的代码在不加载选择列表时会给出错误“加载列表时出错”

$(document).ready(function () {

    var viewModel = function () {
        var self = this;
        self.id = ko.observable();
        self.firstName = ko.observable();
        self.lastName = ko.observable();

        self.genders = ko.observableArray( [
            { id: 1, text: "Male" },
            { id: 2, Description: "Female"  }
        ]);

        self.gender = ko.observable();
        self.firstName = ko.observable('John');
        self.lastName = ko.observable('Doe');
        self.gender = ko.observable(2);
    }

    ko.applyBindings(new viewModel());

    EditableManager.registerEditable();
    EditableManager.onSuccess = function (result) {

    };

});

HTML

 <span data-type='select' data-showbuttons="false"  data-bind=" editable: gender,  editableOptions: {pk: id, options: genders, optionsText: 'text', optionsValue: 'id'}"></span>

对此的任何帮助将不胜感激,

-乔治

【问题讨论】:

    标签: knockout.js x-editable


    【解决方案1】:

    在editableOptions中,将'options'改为'source'。

    在 self.genders 中,使用 'value' 和 'text' 定义对象键,因为我无法让 optionsText 和 optionsValue 工作。

    在 x-editable 中将名称更改为 default options 后,它应该可以工作 (JS Bin)。

    【讨论】:

    • 后来想通了,以下作品仅供参考
    【解决方案2】:

    如果您想使用参数options,您需要稍微不同地配置它,如果您将ko.mapping.fromJS 用于您的对象/数组,这一点尤其重要

    视图模型

    ko.mapping.fromJS({
       selected: "a",
       myoptions: [{text:"AA", value:"a"},{text:"BB", value:"b"}]
    })
    

    选择

    data-bind=" editable:selected, editableOptions:{
        type:'select', 
        options:myoptions, 
        optionText:'text', 
        optionsValue:'value'} "
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多