简体   繁体   English

嵌入koGrid的下拉列表不起作用

[英]Drop down list embedded in koGrid not working

I am trying to get a drop down list to populate on each row of a koGrid. 我正在尝试获取一个下拉列表,以填充到koGrid的每一行上。 Here is the jsFiddle to illistrate (notice how there is no text in the drop down boxes)- http://jsfiddle.net/wood0615/sorg9na0/2/ 这是要说明的jsFiddle(请注意下拉框中没有文本)-http: //jsfiddle.net/wood0615/sorg9na0/2/

Here is my html- 这是我的html-

     <table border="0" style="width: 100%;">
    <tr>           
       <td colspan="6">
            <div class="gridStyle" data-bind="koGrid: gridOptions">&nbsp;</div>
       </td>

    </tr>
</table>

My viewmodel- 我的视图模型

 function mainVm(){
this.WQOptions = ko.observableArray( [
                { decision: 'Approve', decisionValue: '10' },
                { decision: 'Pend', decisionValue: '5' }
    ]);

this.myData = ko.observableArray([
                { name: 'Jack Frost', age: '30' },
                { name: 'John Doe', age: '50' }]);

this.gridOptions = { 
    data: this.myData,
    autogenerateColumns: false,
    columnDefs: [
        {
            field: "name", 
            displayName: "Name"
        },
        {
            displayName: "Decision",
            cellTemplate: "<select id='Select6' data-bind=\" options: $parent.entity.WQOptions, optionsValue: $data.decisionValue, optionsText: $data.decision \"></select>"
        }

    ]
};
 };

 ko.applyBindings(new mainVm());

any idea on why the drop down boxes are empty without data? 关于为什么下拉框为空而没有数据的任何想法?

To access the viewmodel used to build the grid, you should use $userViewModel : 要访问用于构建网格的viewmodel,应使用$userViewModel

cellTemplate: "<select id=\"Select6\" \
                       data-bind=\" options: $userViewModel.WQOptions, \
                                    optionsValue: 'decisionValue', \
                                    optionsText: 'decision' \"> \
               </select>"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM