Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法从knockout.js选择列表中访问值_Javascript_Knockout.js - Fatal编程技术网

Javascript 无法从knockout.js选择列表中访问值

Javascript 无法从knockout.js选择列表中访问值,javascript,knockout.js,Javascript,Knockout.js,我无法访问knockout.JS选择列表中的值 <select data-bind="value: cardType, optionsCaption: '--', options: $root.cardTypeList, optionsText: 'type'"></select> self.cardTypeList = [{type: 'Visa'}, {type: 'MasterCard'}, {type: 'American

我无法访问knockout.JS选择列表中的值

<select data-bind="value: cardType,
    optionsCaption: '--',
    options: $root.cardTypeList,
    optionsText: 'type'"></select>

self.cardTypeList = [{type: 'Visa'},
    {type: 'MasterCard'},
    {type: 'American Express'}];
self.cardType = ko.observable("").extend({ required: true });
如果我从列表中选择MasterCard,然后在firefox中使用
警报(self.cardType().toSource())
,它会显示
({type:“MasterCard”})


我知道它正在被设置,我只是不知道如何访问它。

您的
cardTypeList
是一个对象列表,因此,要访问选定的
cardType
,您应该执行以下操作:

 var yourSelectedCardType = self.cardType().type;
 var yourSelectedCardType = self.cardType().type;