当在下拉列表中单击列表中的值时,如何使用Sharepoint上的Knockout,可以看到div?

时间:2015-01-29 10:48:18

标签: javascript jquery sharepoint knockout.js

Application: 
<select data-bind="value: $data.selectedApp, options: $parent.applications, optionsText: 'ApplicationName', optionsCaption: 'Choose an Application'" style="width: 32px" name="Application list" id="dataBox">
</select>

有了这个,我正试图制作

<Div = "main">...</div>     
单击“USB访问请求”下拉列表时,

可见 我的javascript:

<script>
    var viewModel = {
        selectedChoice: ko.observable("USB Read/Write") ,
        selectionChanged: function(event) {
            show( "main" );  
        } 
    };
    ko.applyBindings(viewModel);   
</script>

1 个答案:

答案 0 :(得分:0)

您可能正在寻找类似的东西

查看型号:

   var viewModel = function () {
       var self = this;
       self.selectedApp = ko.observable();
       self.applications = ko.observableArray([{
           "ApplicationName": "application1"},{
               "ApplicationName": "application2"},{
                   "ApplicationName": "application3"}
       ]);
   };
   ko.applyBindings(new viewModel())

查看:

Application:
<select data-bind="value:selectedApp,options:applications,optionsText:'ApplicationName',optionsCaption:'Choose an Application'" style="width: 160px"></select>

<div data-bind="if:selectedApp">
     <h2>i'm Main DIV</h2>
</div>

我看到html很简单,所以在这种情况下使用if绑定总是更好。

工作小提琴 here

任何问题都告诉我们