Reputation: 4908
So this is my select2 input
<input type="hidden" ng-model="ProjectTagpr" class="input-large" ui-select2="tagOptions" />
where in tagOptions
is
{
data: [{"id":301,"text":"tag2"},{"id":302,"text":"tag2"},{"id":303,"text":"tag3"},{"id":304,"text":"tag4"}],
multiple: true,
createSearchChoice: function(term) {
var timestamp = new Date().getTime();
return {id: timestamp, text: term, new: true};
}
}
and ProjectTagpr
is
[301, 304];
which renders select2 with tags tag1, tag4
and turns ProjectTagpr
to
[{"id":301,"text":"tag2"},{"id":304,"text":"tag4"}]
Now the first question
Can I make it so it keeps the original ProjectTagpr
structure(just an array of ids, instead of object with both id and text)?
And the second question
If I add a new tag, say newtag5
, it would expand ProjectTagpr
with something like {id: 1554894854, text: 'newtag5', new: true}
, now when I press save and I'd like my $http to update the original data
on the select2, so it adds the newtag5 there(of course returned with id from database and without that new: true
), how would I do this?
I tried to do $scope.tagOptions.data = dataReturnedFromHttp;
but that obviously(or not) didn't work..
Upvotes: 2
Views: 1997
Reputation: 4908
It's actually fairly simple
data: function() {
return {'results': $scope.data};
}
then it's pretty much live-binded.
It's just that it's somehow undocumented, that you can pass data a function..
Upvotes: 4