devlife
devlife

Reputation: 16145

Why isn't my select list selected option being set when using knockoutjs?

I'm able to successfully set the options for my select list but the selected option isn't being set.

Can anyone see what I'm doing wrong?

http://jsfiddle.net/devlife/YmshY/2/

Html:

<select data-bind="options: FundTypeOptions, optionsText: 'Text', optionsValue: 'Value', value: 

Javscript:

$root.SelectedFundType"></select>​

$(function(){

    var options = {
        "ImportType":0,

        "ImportTypeList":{
            "":"",
            "Funds":"Fund Level Investments",
            "Valuations":"Valuations"
        },

        "FundTypeOptions":[
            {"Value":"","Text":""},
            {"Value":"Initial","Text":"Initial"},
            {"Value":"FollowOn","Text":"Follow-on"}
        ],

        "SelectedImportType":"Funds",

        SelectedFundType: "FollowOn"
    };

    var viewModel = {

        FundTypeOptions: ko.observableArray(options.FundTypeOptions)

    };

    ko.applyBindings(viewModel);
});​

Upvotes: 0

Views: 1014

Answers (1)

madcapnmckay
madcapnmckay

Reputation: 15984

Your SelectedFundType is not a property of your viewModel.

var viewModel = {

    FundTypeOptions: ko.observableArray(options.FundTypeOptions),
    SelectedFundType: ko.observable("FollowOn")
};

http://jsfiddle.net/h8mfK/1/

Hope this helps.

Upvotes: 1

Related Questions