棱角分明的UI SELECT2标记更新的数据值 [英] angular-ui select2 tagging update the data value

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

问题描述

所以这是我选择2输入

<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];

这使得与标记选择2 标记1,TAG4 ,并转 ProjectTagpr

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

现在的第一个问题
我可以做它,所以它(既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 ,它会展开 ProjectTagpr 的东西,如 { ID:1554894854,文本:newtag5,新:真正} ,现在当我preSS保存,我想我的$ HTTP更新原有数据在SELECT2,所以它增加了newtag5存在(当然返回id为从数据库没有这种新:真正的),我会怎么做?

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

那么它的pretty多活绑定。

then it's pretty much live-binded.

这只是它的无证某种程度上,你可以传递数据的功能。

It's just that it's somehow undocumented, that you can pass data a function..

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

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