如何在淘汰赛中声明变量内联?我声明someValue的方式给了我错误。
<input data-bind="textInput : new someValue ,event: {keypress: enterSearch}" class="form-control" placeholder="Jump to ...">
<button type="button" class="btn btn-default" data-bind="click: $root.selectPage.bind($data, someValue)"> Search! </button>
答案 0 :(得分:0)
HTML:
<input data-bind="value: page" class="form-control" placeholder="Jump to ...">
<button type="button" class="btn btn-default" data-bind="click: selectPage"> Search! </button>
viewmodel(约):
var viewmodel = function() {
var page = ko.observable();
var selectPage = function() {
// just use page() here instead of passing it as a parameter
};
return {
page: page,
selectPage: selectPage
}
}