我有一个简单的knockout.js应用程序:
视图:
这个简单的ViewModel:
我期望,在我点击“CLEAR VALUE!”的span后,select中将选择选项“choose...”,但实际上没有发生。viewModel中的值被设置为空字符串,这是正确的,但用户仍然看到旧值在select中。
有什么办法可以解决吗?
谢谢你的帮助 :)
视图:
<select data-bind="options: allDocumentTypes , optionsCaption: 'Choose ...', optionsValue: 'id', optionsText: 'name', selectedOptions: selectedDocument"></select>
<span data-bind="click: cl">CLEAR VALUE!</span>
这个简单的ViewModel:
function documentType(id, name){
this.id = id;
this.name = name;
}
var viewModel = {
allDocumentTypes: ko.observableArray([]),
selectedDocument: ko.observable(''),
cl: function(){
viewModel.selectedDocument('');
}
};
/* load data */
viewModel.allDocumentTypes.push(new documentType(1,'Test 1'));
viewModel.allDocumentTypes.push(new documentType(2,'Test 2'));
ko.applyBindings(viewModel);
我期望,在我点击“CLEAR VALUE!”的span后,select中将选择选项“choose...”,但实际上没有发生。viewModel中的值被设置为空字符串,这是正确的,但用户仍然看到旧值在select中。
有什么办法可以解决吗?
谢谢你的帮助 :)