【问题标题】:oj-select-one show undefined for all optionsoj-select-one 显示未定义的所有选项
【发布时间】:2018-07-27 16:30:02
【问题描述】:

我有一个从 REST 获取值的可观察数组

$.getJSON(rootModel.soho()).
        then(function (StudentCourseView1) {
            $.each(StudentCourseView1.items, function () {
                self.data.push({
                    StudentId: this.StudentId,
                    CourseId: this.CourseId,
                    Enrollmentdate :this.Enrollmentdate,
                    Notes :this.Notes,
                    Id : this.Id,
                    CourseName : this.CourseName,
                    StudentName: this.StudentName
                });
            });
                    });
             self.dataSource = new oj.ArrayTableDataSource(
              self.data, 
              {idAttribute: 'Id'}
      );

我已经创建了这样的 select-one

 <oj-select-one id="select1" style="max-width:20em"
                 options={{data}}
                 value="{{data.Id}}"
                 options-keys="[[data.StudentName]]" >
</oj-select-one>

选择一个显示未定义的所有选项

【问题讨论】:

    标签: javascript knockout.js oracle-jet


    【解决方案1】:

    您确定 ajax 调用正常工作,并且控制台中没有错误吗?下拉列表是否显示空白值列表?

    如果是,那么唯一缺少的元素是添加option-keys 属性,以说明要向用户显示哪些数据,以及每条数据的键。

    <oj-select-one id="select1" style="max-width:20em"
                     options={{data}}
                     options-keys="{{optionKeys}}" 
                     value="{{StudentId}}">
    

    JS

    //You can change this acc. to your convenience.
    self.optionKeys = {value:"Id", label:"StudentName"}; 
    

    【讨论】:

    • 控制台是空的,选择一个不呈现在页面上的我没有得到使用 self.optionKeys = {value:"Id", label:"StudentName"};你能详细说明一下吗?
    • options-keys 用于告诉oj-select-one 组件self.data 的哪两个属性将用于 1) 存储所选值 2) 在 UI 中显示值。但是,如果您说 oj-select-one 根本没有渲染,那么问题就出在其他地方。您是否在定义块中导入了“ojs/ojselectcombobox”?您是否将StudentId 定义为可观察对象?
    • studentId 来自可观察数组中由 json 填充的部分。我添加了“ofj/ojselectcombobox”控制台打印以下错误未捕获(承诺)ReferenceError:无法处理绑定“_ojCustomElement:function(){return {composite:info.composite}}”消息:未定义StudentId。并且 html 将 options-keys="{{optionKeys}}" 显示为静态文本
    • 你需要单独定义一个observable来保存选中项的值。将self.studentId = ko.observable(); 添加到您的代码中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    • 2014-08-11
    • 1970-01-01
    • 2018-05-05
    • 2020-10-24
    • 2022-09-30
    相关资源
    最近更新 更多