选择二标签输入值丢失AngularJS [英] Select2 tagging input loses value AngularJS
本文介绍了选择二标签输入值丢失AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有切换的意见与 NG-开关
应用程序,同时切换视图我的标签输入专门失去了它的价值,属于它的对象的字符串,没有我的其他投入受此问题:
I have an app that switches views with ng-switch
, while switching views my tagging input specifically loses its value and falls into its object string, none of my other inputs suffer this issue:
HTML:
<input ui-select2="version2"
id="keywordsGlobal"
name="keywordsGlobal"
class="region-keywords input-xlarge"
data-ng-model="data.keywordsGlobal"
required-multiple />
JSON:
[
{
"id":"[object Object]",
"text":"[object Object]"
}
]
有什么办法prevent这个特别?
Is there any way to prevent this specifically?
推荐答案
中的数据似乎没有要对选择的后续装载正确加载。使用 initSelect()
并手动重新分配数据出现选择来解决该问题。
The data didn't appear to be loaded correctly on subsequent loading of the select. Using initSelect()
and manually re-assigning the data to the select appears to fix the issue.
看看 http://jsfiddle.net/qdrjk/111/
$scope.version2 = {
tags : null,
initSelection: function(elem, callback) {
console.log(elem);
var data = $scope.data.keywordsGlobal;
callback(data);
},
createSearchChoice : function(term, data) {
if ($(data).filter(function() {
return this.text.localeCompare(term) === 0;
}).length === 0) {
return {
id : term,
text : term
};
}
}
}
这篇关于选择二标签输入值丢失AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文