Event handlers for Twitter Bootstrap dropdowns?

前端 未结 7 2075
不思量自难忘°
不思量自难忘° 2020-12-14 04:59

I\'d like to use a Twitter Bootstrap dropdown button:

    
7条回答
  •  伪装坚强ぢ
    2020-12-14 05:55

    Anyone here looking for Knockout JS integration.

    Given the following HTML (Standard Bootstrap dropdown button):

    
    

    Use the following JS:

    var viewModel = function(){
        var self = this;
    
        self.clickTest = function(){
            alert("I've been clicked!");
        }  
    };
    

    For those looking to generate dropdown options based on knockout observable array, the code would look something like:

    var viewModel = function(){
        var self = this;
    
        self.dropdownOptions = ko.observableArray([
            { id: 1, label: "Click 1" },
            { id: 2, label: "Click 2" },
            { id: 3, label: "Click 3" }
        ])
    
        self.clickTest = function(item){
            alert("Item with id:" + item.id + " was clicked!");
        }  
    };
    
    
    
    
    

    Note, that the observable array item is implicitly passed into the click function handler for use in the view model code.

提交回复
热议问题