在客户端的PnP分类选择器控件中设置值

时间:2019-03-14 11:43:35

标签: sharepoint-online taxonomy

我在页面中的在线SharePoint中有2个PnP分类法选择器控件。我将这些控件初始化如下

$('#taxPickerKeywords_' + p).taxpicker({
 isMulti: false, 
 allowFillIn: true, 
 useKeywords: true, 
 termSetId: 'GUID'
}, context);

现在我需要将第二个控件的值设置为第一个控件的值。我可以从第一个控件获取值,但无法在jQuery中使用.val()设置第二个控件值。

初始化我的纳税人选择器后,HTML如下所示

<div class="cam-taxpicker">
  <div class="cam-taxpicker-editor" contenteditable="true"></div>
  <div class="cam-taxpicker-button"></div>
  <input type="hidden" id="taxPickerKeywords_0">
</div>
<div class="cam-taxpicker-suggestion-container"></div>

有任何想法或建议来设置此控件的值吗?

1 个答案:

答案 0 :(得分:0)

我为此做了一个解决方法。该值已使用$('#tax_2').val(value);进行了设置,但未出现在编辑器中。因此,我更新了它的值,然后将编辑器元素设置为第一个税收选择器中的元素。

//setting the value of 2nd control
$('#tax_2').val(value);

//cloning the elements of 1st control's editor
var clonedVar = $('#tax_1').parent().find('.cam-taxpicker-editor').children().clone();

//emptying the 2nd control's editor if any other value is present
$('#tax_2').parent().find('.cam-taxpicker-editor').empty();

//appending the editor element to 2nd control
$('#tax_2').parent().find('.cam-taxpicker-editor').append(clonedVar);

这对我有用,因为我正在复制一个分类选择器中已经存在的值。我也能够读取这些值并将其保存到后端。用户甚至可以在复制后更改该值。

相关问题