我已经订阅了使用 ko 监听属性值变化的函数。
var self = this;
$( document ).ready( function () {
var postbox = new ko.subscribable();
var myViewModel =
{
FirstName: ko.observable( "Bert" ),
LastName: ko.observable( "pual" )
};
var sub = null;
for ( var i in myViewModel ) {
var model = myViewModel[i];
model.subscribe( self.notifyChange.bind( model, i ) );
}
$( '#unsubscribeButton' ).click( function () {
// here i want to unsubscribe.
} );
ko.applyBindings( myViewModel );
});
notifyChange = function ( PropName, newValue ) {
var self= this;
);
}
这里我想从myViewModel的属性中一一退订notifyChange,怎么做呢?