0

我认为这更像是一个 jquery 集成问题,但这是我的问题/错误。我正在尝试将 [bootstrap-tokenfield][1] 包装为聚合物元素,但出现以下错误/跟踪:

Error: An attempt was made to reference a Node in a context where it does not exist.
  at GeneratedWrapper.mixin.insertBefore (http://localhost:3005/ShadowDOM/src/wrappers/Node.js:266:30)
  at Object.<anonymous> (http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js:6067:21)
  at jQuery.fn.extend.domManip (http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js:6262:15)
  at jQuery.fn.extend.before (http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js:6065:15)
  at Tokenfield.createToken (http://localhost:3005/elements/ui-widgets/bootstrap-tokenfield/bootstrap-tokenfield.js:175:21)

编码:

<polymer-element name="my-bootstrap-tokenfield">
  <template>
    <link rel="stylesheet" href="bootstrap-tokenfield.css">
    <input type="text" class="form-control" id="tokenfield" value="red,green,blue" />
  </template>
  <script src="bootstrap-tokenfield.js"></script>
  <script>
    Polymer('my-bootstrap-tokenfield', {
      applyAuthorStyles : true, 
      ready : function() {
        // default example
        $(this.$.tokenfield).tokenfield({
           typeahead: {
               name: 'tags',
               local: ['red','blue','green','yellow','violet','brown','purple','black','white'],
           },
           allowDuplicates: true
        });
      }
    })
  </script>
</polymer-element>

想法、建议?

4

1 回答 1

1

感谢 ebidel 帮助我解决问题。将输入包装在“div”标签中,一切都很好。作为构建小部件的“输入”父级的令牌字段是有意义的。

<template>
    <link rel="stylesheet" href="bootstrap-tokenfield.css">
    <div>
       <input type="text" class="form-control" id="tokenfield" value="red,green,blue" />
    </div>
</template>
于 2014-05-20T21:26:32.787 回答