angular-ui select2 标记更新数据值 [英] angular-ui select2 tagging update the data value

查看:25
本文介绍了angular-ui select2 标记更新数据值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 select2 输入

So this is my select2 input

<input type="hidden" ng-model="ProjectTagpr" class="input-large" ui-select2="tagOptions" />

tagOptions 中的位置是

{
    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};
    }
}

ProjectTagpr

[301, 304];

呈现带有标签 tag1, tag4 的 select2 并转 ProjectTagpr

which renders select2 with tags tag1, tag4 and turns ProjectTagpr to

[{"id":301,"text":"tag2"},{"id":304,"text":"tag4"}]

现在是第一个问题我可以让它保持原始的 ProjectTagpr 结构(只是一个 id 数组,而不是具有 id 和文本的对象)?

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)?

第二个问题如果我添加一个新标签,比如 newtag5,它会用类似 {id: 1554894854, text: 'newtag5', new: true}<的内容扩展 ProjectTagpr/code>,现在当我按保存时,我希望我的 $http 更新 select2 上的原始 data,所以它在那里添加了 newtag5(当然从数据库中返回了 id,没有那个new: true),我该怎么做?

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?

我试图做 $scope.tagOptions.data = dataReturnedFromHttp; 但显然(或不)不起作用..

I tried to do $scope.tagOptions.data = dataReturnedFromHttp; but that obviously(or not) didn't work..

推荐答案

其实很简单

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..

这篇关于angular-ui select2 标记更新数据值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆