grep(pattern = "a", x = c("abcdef", "bcdf"), value = TRUE)
[1] "abcdef"
除了我得到之外,这是有效的:
<input data-bind="value: fileName" type="file" multiple="">
<input data-bind="value: fileName" type="text" readonly="">
因为当我只想读取它并将其写入文本输入时,它会尝试设置文件输入的值。
http://jsfiddle.net/esk5akwj/2/
答案 0 :(得分:1)
由于文件选择器值只能通过使用文件选择器设置,并且必须以空字符串开头,因此需要一个包装value
绑定的自定义绑定处理程序,并在init上设置绑定值为空字符串:
ko.bindingHandlers.resetValue = {
init: function(element, valueAccessor, allBindingsAccessor, data, context) {
valueAccessor()('');
ko.bindingHandlers.value.init(element, valueAccessor, allBindingsAccessor, data, context);
},
update: function(element, valueAccessor, allBindingsAccessor, data, context) {
ko.bindingHandlers.value.update(element, valueAccessor, allBindingsAccessor, data, context);
}
};
ko.applyBindings({
fileName: ko.observable(),
c: ko.observable()
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<input data-bind="checked: c" type="checkbox">Check me, choose a file, uncheck me, check me, choose a file.
<!-- ko if: c -->
<input data-bind="resetValue: fileName" type="file" multiple="">
<input data-bind="value: fileName" type="text" readonly>
<!-- /ko -->