首页 > 解决方案 > oj-select-one 显示未定义的所有选项

问题描述

我有一个可观察的数组,它从 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'}
      );

我已经创建了这样的选择

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

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

标签: javascriptknockout.jsoracle-jet

解决方案


您确定 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"}; 

推荐阅读