选项没有显示在complete.ly库中

时间:2018-04-27 09:31:23

标签: javascript complete.ly

我设置了一个非常简单的var strategyChoice = ["a", "b", "c"]; $(function() { var pv = completely(document.getElementById('container')); pv.onChange = function(text) { console.log(text); if (text === 'i') { pv.setText('I want to'); // special case i becomes 'I want to'. return; } if (text === 'I want to ') { pv.options = ["pay", "receive"]; pv.repaint(); console.log(pv.options); return; } if (["I want to pay ", "I want to receive "].includes(text)) { pv.options = strategyChoice; pv.repaint(); console.log(pv.options); return; } } 文本框但我的选项没有显示。 我怀疑我错过了一些明显的东西。

这是一个非常基本的例子:

  'single_cell = tf.contrib.rnn.core_rnn_cell.GRUCell(size)'

fiddle显示了此问题。

1 个答案:

答案 0 :(得分:1)

看起来您的主要问题是:

a)忘记将'startFrom'属性设置为当前输入文本的长度

b)忘记在某些选项值的末尾添加空格

以下是您的示例的稍作版本:

var strategyChoice = ['a', 'b', 'c'];
var pv = completely(document.getElementById('container'),{color:'black'});

pv.onChange = function(text) {
  if (text === 'i' || text === 'I') {
    pv.setText('I want to ');
    return;
  }
  if (text === 'I want to ') {
    pv.options = ['pay ', 'receive '];
    pv.startFrom = text.length;
    pv.repaint();
    return;
  }
  if (['I want to pay ', 'I want to receive '].includes(text)) {
    pv.options = strategyChoice;
    pv.startFrom = text.length;
    pv.repaint();
    return;
  }
};

pv.options = ['I want to pay ', 'I want to receive '];

setTimeout(function() {
  pv.input.focus();
  pv.setText('I ');
  pv.repaint();
}, 0);
<script src="https://lorenzoongithub.github.io/completely/complete.ly.1.0.1.min.js"></script>
<div id='container'></div>