1

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

  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>
​

这是在线代码: http: //jsfiddle.net/shahr0oz/K4X3T/19/ ​</p>

4

1 回答 1

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/

于 2012-10-10T19:36:53.477 回答