Knockout 和 viewModel 的问题
Problems with Knockout and viewModel
我的观点如下:
<div data-bind="dxTextBox: { onFocusIn: onEnterSearch, placeholder: 'suche...', showClearButton: true , value: ''}"></div>
<div data-bind="dxButton: { onClick: 'SearchCustomer', text: 'suchen' }" style="width:100%;"></div></div>
这在我的 js 文件中:
function DoSearch() { alert('DoSearch');}
function clearSearch() {
alert('clearSearch');
}
var viewModel = {
//// Put the binding properties here
SearchCustomer: DoSearch,
onEnterSearch: clearSearch
};
return viewModel;
但是现在,当我聚焦文本框时,我收到警报 'clearSearch',然后单击按钮时,我收到 404 错误。
有人知道吗?
谢谢
帕特里克
据此article:
When defining a widget, specify a URL (a string or an object) as a handler for a widget event (assign the URL to the corresponding option or pass it as a parameter to the on method). For a better UI design, navigate to views using the events that fire as a result of clicking a widget or a widget element.
因此,此事件处理程序 onClick: 'SearchCustomer'
会将您导航到未定义的 'SearchCustomer' 视图。
如果您想使用 viewModel.SearchCustomer
方法作为 onClick
事件处理程序,只需从绑定字符串中删除引号:
<div data-bind="dxButton: { onClick: SearchCustomer, text: 'suchen' }"></div>
也请参阅此 fiddle。
我的观点如下:
<div data-bind="dxTextBox: { onFocusIn: onEnterSearch, placeholder: 'suche...', showClearButton: true , value: ''}"></div>
<div data-bind="dxButton: { onClick: 'SearchCustomer', text: 'suchen' }" style="width:100%;"></div></div>
这在我的 js 文件中:
function DoSearch() { alert('DoSearch');}
function clearSearch() {
alert('clearSearch');
}
var viewModel = {
//// Put the binding properties here
SearchCustomer: DoSearch,
onEnterSearch: clearSearch
};
return viewModel;
但是现在,当我聚焦文本框时,我收到警报 'clearSearch',然后单击按钮时,我收到 404 错误。
有人知道吗?
谢谢 帕特里克
据此article:
When defining a widget, specify a URL (a string or an object) as a handler for a widget event (assign the URL to the corresponding option or pass it as a parameter to the on method). For a better UI design, navigate to views using the events that fire as a result of clicking a widget or a widget element.
因此,此事件处理程序 onClick: 'SearchCustomer'
会将您导航到未定义的 'SearchCustomer' 视图。
如果您想使用 viewModel.SearchCustomer
方法作为 onClick
事件处理程序,只需从绑定字符串中删除引号:
<div data-bind="dxButton: { onClick: SearchCustomer, text: 'suchen' }"></div>
也请参阅此 fiddle。