knockout.js - Autocomplete updated source is not reflecting in Knockout JS -
i have implemented autocomplete in knockout js project using example
http://cameron-verhelst.be/blog/2014/04/20/knockoutjs-autocomplete/
it working populated source data. later on have changed source data on focus event of text box on autocomplete applied.but auto complete pop not populating updated source data. binding
<input class="form-control" type="text" style="margin-right:15px;border:0px;" data-bind="value:conditiondata,event:{ focus:assignautocompletearray },autocomplete: {selected:selectedoption, options:options}" placeholder="key">
and changing source way
self.assignautocompletearray = function (attribute) { debugger; var attr = attribute; var tokenlistdata = ruletokenlist.map(function (element) { return { label: element.label, value: element.value, object: element }; }); attribute.options = ko.observablearray(tokenlistdata); }
my view model
var criteria = function () { debugger; var self = this; self.id = ko.observable(); self.conditiondata = ko.observable(); self.value = ko.observable(); self.andor = ko.observable(); self.operator = ko.observable(); self.children = ko.observablearray([]); self.andorlist = ko.observablearray([{ key: 'and', value: 'and' }, { key: 'or', value: 'or' }]); self.operators = ko.observablearray(operatorlist); self.isactive = ko.observable(); self.isvisibleaddchild = ko.observable(false); self.selectedoption = ko.observable(''); self.options = ruletokenlist.map(function (element) { return { label: element.label, value: element.value, object: element }; }); self.addchildattribute = function () { var newattr = new criteria(); self.children.push(newattr); } self.savefilter = function (attribute) { self.isvisibleaddchild(true); } self.assignautocompletearray = function (attribute) { debugger; var self = this; var tokenlistdata = ruletokenlist.map(function (element) { return { label: element.label, value: element.value, object: element }; }); } }
what issue
thanks utpal
you replacing observablearray instead of changing out contents. 1 knockout had bound no longer there. should do
attribute.options(tokenlistdata);
to give new contents.
Comments
Post a Comment