如何在Ractive.js中绑定变量window ['array [element]']?

时间:2018-08-21 05:18:07

标签: ractivejs

需要对具有非典型名称(例如“ array [element]”)的变量进行双向绑定。

以下语法有效,但是当我将0更改为@index时,它会损坏。在方括号[]之前添加反斜杠效果不佳。

<input type="text" name="prices[{{@index}}]" value="{{someForm.inputs["prices[0]"].value}}" />

绑定变量的正确语法是什么?

1 个答案:

答案 0 :(得分:0)

您可以使用@context

Ractive.DEBUG = false;
var ractive = Ractive({
  target: output,
  template: `
    {{ @context.get('array[element]') }}
  `,
  data: { 'array[element]': "FOO" }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/ractive/1.0.0-build-99/ractive.min.js"></script>
<div id="output"></div>