【问题标题】:Set value in PnP taxonomy picker control on client side在客户端的 PnP 分类选择器控件中设置值
【发布时间】:2019-03-15 19:07:01
【问题描述】:

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

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

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

初始化我的 taxpicker 后,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>

对于设置此控件的值有什么想法或建议吗?

【问题讨论】:

    标签: sharepoint-online taxonomy


    【解决方案1】:

    我为此做了一个解决方法。该值是使用$('#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);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多