3

I can't seem to figure out how to pass my variable into the class, ID, or data attributes on my custom element.

<ub-item class="item cssV2 { opts.status }" id="{ opts.id }" data-link="{ opts.url }">

opts.status, opts.id, and opts.url all work if I pass them in an element like <p>, but how do I pass the variable into the attributes? The HTML output includes them as strings.

4

2 回答 2

3

应使用以下方法创建将在标签中使用的变量:

<mytag>
 <p class="{ myclass: show }" id="{ myid }" data-link="{ mydata }">Example</p>

 <script>
   this.mydata = 'foo'
   this.myid = 'bar'
   this.show = true
 </script>
</mytag>

这将呈现为:

 <mytag>
  <p class="myclass" id="bar" data-link="foo">Example</p>
 </mytag>
于 2015-10-10T06:49:16.107 回答
0

我的猜测,因为我担心没有提供进一步的信息。

也许您只需将选项分配给 self/this 以使它们可用于视图。

self = this
self.opts = opts

如果参数发生变化:

self.on('update', function(){
  self.opts = opts
})
于 2015-06-17T20:31:17.717 回答