通过mvvm将复选框列表绑定到kendo ui中的下拉列表

时间:2012-10-07 16:05:00

标签: mvvm kendo-ui

我想在我的视图中有一个下拉列表。我希望在更改我的下拉列表时,一个java脚本模板绑定dropdownlist.i写下这个但是不要工作请求帮助我。

  var  roles=[{
        code:1,
        roleName: "Admin",
        access: [ 
            { id: 1, description: "create", selected: true}, 
            {id: 2, description: "delete", selected: false}, 
            { id: 3, description: "update", selected: false}
        ]
    } ,{
        code:2,
        roleName: "user",
        access: [ 
            { id: 1, description: "create", selected: true}, 
            {id: 2, description: "delete", selected: true}, 
            { id: 3, description: "update", selected: false}
        ]
    }];
var viewModel = kendo.observable({
    Roles:roles,
    role:"Admin",
    accessRole:null    
});

kendo.bind($("#example"), viewModel);

这是我的观点代码

<div id="example">
     Current Role&nbsp;&nbsp;&nbsp;:<span data-bind="text: role"></span>
    <br>
    <select type="text" id="RoleName" data-bind="source: Roles, value:role"  data-text-field="roleName">

   <select/>

        <ul data-template="row-template" data-bind="source: accessRole.access"></ul>

</div>

<script id="row-template" type="text/x-kendo-template">
    <li>
        <input type="checkbox" data-bind="checked: selected" />
        <label data-bind="text: description" />
    </li>
</script>
​

这是onlne代码: http://jsfiddle.net/shahr0oz/K4X3T/19/

1 个答案:

答案 0 :(得分:3)

我明白了。

<div id="example">
     Current Role&nbsp;&nbsp;&nbsp;:<span data-bind="text: role.roleName"></span>
    <br>
    <select type="text" data-bind="source: Roles,value:role}"  data-text-field="roleName">

   <select/>

        <ul data-template="row-template" data-bind="source:role.access"></ul>

</div>

<script id="row-template" type="text/x-kendo-template">
    <li>
        <input type="checkbox" data-bind="checked: selected" />
        <label data-bind="text: description" />
    </li>
</script>

​    var  roles=[{
        code:1,
        roleName: "Admin",
        access: [ 
            { id: 1, description: "create", selected: true}, 
            {id: 2, description: "delete", selected: true}, 
            { id: 3, description: "update", selected: false}
        ]
    } ,{
        code:2,
        roleName: "user",
        access: [ 
            { id: 1, description: "create", selected: false}, 
            {id: 2, description: "delete", selected: false}, 
            { id: 3, description: "update", selected: false}
        ]
    }];
var viewModel = kendo.observable({
    Roles:roles,
    role:roles[0]
});


kendo.bind($("#example"), viewModel);

http://jsfiddle.net/shahr0oz/psEVy/