subscribe
函数被再次调用,对吗?
在这种情况下,如果
return Component.extend({
defaults: {
changeTextValue: ko.observable(),
currentRequest: null,
anotherObservableArray: [],
subscription: null,
tracks: {
changeTextValue: true
}
},
initialize: function() {
this._super();
},
doSomething: function(config) {
var self = this;
if (this.subscription)
this.subscription.dispose();
this.subscription = this.changeTextValue.subscribe(function(newValue) {
if (self.currentRequest) {
self.currentRequest.abort();
}
self.currentRequest = $.ajax({
url: urlBuilder.build('abc/temp/temp'),
type: 'POST',
data: JSON.stringify({
'searchtext': newValue
}),
global: true,
contentType: 'application/json',
success: function(response) {
var json_data = JSON.parse(response);
self.autocompleteData.removeAll();
$.each(json_data, function(key, val) {
self.autocompleteData.push({
productID: val.productID
});
});
},
error: function(jqXHR, exception) {
alert("Not OK!")
}
});
});
},
});
ko.applyBindings(new CeremonyViewModel());