admin管理员组文章数量:1426643
Using Aurelia, is it possible to use a variable name to dynamically reference a model object's property name?
Javascript:
dow = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];
test = {
monday: false,
tuesday: false,
wednesday: false,
thursday: false,
friday: false,
};
HTML:
<label repeat.for="day of dow"><input type="checkbox" class="form-control" checked.bind="test[day]" />${day}</label>
This results in: "TypeError: obj is undefined"
Using Aurelia, is it possible to use a variable name to dynamically reference a model object's property name?
Javascript:
dow = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];
test = {
monday: false,
tuesday: false,
wednesday: false,
thursday: false,
friday: false,
};
HTML:
<label repeat.for="day of dow"><input type="checkbox" class="form-control" checked.bind="test[day]" />${day}</label>
This results in: "TypeError: obj is undefined"
Share Improve this question edited Sep 1, 2015 at 2:46 billcobbler asked Sep 1, 2015 at 2:02 billcobblerbillcobbler 3151 silver badge8 bronze badges 01 Answer
Reset to default 8According to the Aurelia Docs:
Each item that is being repeated by the repeat attribute has several special contextual values available for binding:
$parent - At present, the main view model's properties and methods are not visible from within the repeated item. We hope to remedy this in an update soon. For the mean time, you can access that view-model with $parent.
$index - The index of the item in the array.
$first - True if the item is the first item in the array.
$last - True if the item is the last item in the array.
$even - True if the item has an even numbered index.
$odd - True if the item has an odd numbered index.
It worked after updating the HTML to reference parent.new_deal[day]:
<label repeat.for="day of dow"><input type="checkbox" class="checkbox-inline" checked.bind="$parent.new_deal[day]" />${day}</label>
本文标签: javascriptAureliaUsing variable as name of property in data bindingStack Overflow
版权声明:本文标题:javascript - Aurelia - Using variable as name of property in data binding - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745393544a2656710.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论