如何在 jQuery 函数中调用 viewmodel 函数?我只想从 Javascript 函数中调用 viewmodel 函数的函数。
function ContactsViewModel(data) {
var self = this;
// Editable data
self.Contacts = ko.observableArray(JSON.parse(data));
self.limit = ko.observable(20);
self.changeNumber = function(item){
self.limit(self.limit()+20);
self.Contacts.push(item);
}
self.myPostProcessingLogic = function(elements) {
if ($('#KnockOutContacts').children().length === ko.toJS(self.Contacts).length) {
// Only now execute handler
jq();
}
}
}
如何changeNumber
从jscroll
窗格功能调用?
$('.jspScrollable').bind(
'jsp-arrow-change',
function(event, isAtTop, isAtBottom, isAtLeft, isAtRight) {
// Now look at the is* parameters and do what you
// need to do. All four of the is* parameters are booleans.
if(isAtBottom) {
ContactsViewModel.changeNumber();
}
}
);
数据来自服务器
function returnData(url,data,type){
$.post(url, data, function(returnedData) {
if(type == "contacts")
{
ko.applyBindings(new ContactsViewModel(returnedData),$("#KnockOutContacts")[0]);
}
else if(type == "logs")
{
ko.applyBindings(new LogsViewModel(returnedData),$("#KnockOutLogs")[0]);
}
else if(type == "sms")
{
ko.applyBindings(new SmsViewModel(returnedData,"#KnockOutSms"),$("#KnockOutSms")[0]);
ko.applyBindings(new SmsViewModel(returnedData,"#KnockOutSmsData"),$("#KnockOutSmsData")[0]);
}
});
}
提前致谢。