Please see code (Using knockout.js over ASP MVC 3):
self.tags = ko.utils.arrayMap(@Html.Raw(new JavaScriptSerializer().Serialize(Model.Tags)), function(tag) {
return {
label: tag.Name,
value: tag.id
};
});
self.addTag = function(event, ui){
$(event.target).val("");
var tag = ui.item.label;
var id = ui.item.value;
self.selectedTags.push("id: " + id + ", Name: " + tag);
//Delete selected tag here from list
return false;
}
The question is, how can I remove from tags? (I tried using remove(), I encounter an error. But when I try pop(), its successful)
Your tags array is normal array, not observable array, it will have no remove method.
Knockout has helper for normal arrays
or you can use splice (actually ko.utils.arrayRemoveItem uses splice)