事件之外的选项元素的流星值(Meteor value of option element outside of event)

编程入门 行业动态 更新时间:2024-10-24 03:26:11
事件之外的选项元素的流星值(Meteor value of option element outside of event)

我有一个Session值,其中包含我想要在填充Select语句时设置为所选值的帐户的值。 当我尝试使用this.value获取值时,我得到“意外的标识符”。 我怎样才能在事件处理程序之外看到这个?

模板:

<template name="transactions"> <form id="trx_form"> <select id="account_selector"> {{> account_selector}} </select> <br> To or From: <input type="text" value="" size="52" id="to_from"><br> <<input type="submit" value="Save" id="save_trx"> </form> </template> <template name="account_selector"> {{#each accounts}} {{#if selectedAcct}} <option value="{{this}}" SELECTED>{{this}}</option> {{else}} <option value="{{this}}">{{this}}</option> {{/if}} {{/each}} </template>

助手功能:

Template.account_selector.accounts = function() { // account_categories is a Global array of pre-defined categories var pairings = []; for (var b = 0, l = account_categories.length; b < l; b++) { var category= account_categories[b]; var acctName = ""; var accountCursor = account_categories[b].find(); accountCursor.forEach( function(acct) { acctName = acct.acct_name; if (acctName > "") { pairings.push(category + ":" + acctName); } }); } return pairings; }; Template.account_selector.selectedAcct ({ var thisAcct = this.value; ... Unexpected identifier ... });

I have a Session value that contains the value of an account that I want to set as the selected value while populating a Select statement. When I try and get the value using this.value I get "Unexpected identifier". How can I look at this outside of an Event Handler?

Templates:

<template name="transactions"> <form id="trx_form"> <select id="account_selector"> {{> account_selector}} </select> <br> To or From: <input type="text" value="" size="52" id="to_from"><br> <<input type="submit" value="Save" id="save_trx"> </form> </template> <template name="account_selector"> {{#each accounts}} {{#if selectedAcct}} <option value="{{this}}" SELECTED>{{this}}</option> {{else}} <option value="{{this}}">{{this}}</option> {{/if}} {{/each}} </template>

Helper Functions:

Template.account_selector.accounts = function() { // account_categories is a Global array of pre-defined categories var pairings = []; for (var b = 0, l = account_categories.length; b < l; b++) { var category= account_categories[b]; var acctName = ""; var accountCursor = account_categories[b].find(); accountCursor.forEach( function(acct) { acctName = acct.acct_name; if (acctName > "") { pairings.push(category + ":" + acctName); } }); } return pairings; }; Template.account_selector.selectedAcct ({ var thisAcct = this.value; ... Unexpected identifier ... });

最满意答案

在每个把手内部,数据上下文(this)是当前数据元素,而不是dom元素。 在您的情况下,您在表单类别中有一个字符串:accountName,您可以使用该字符串来获取与会话进行比较的名称。

Inside the handlebars each, the data context (this) is the current data element,not dom element. In your case you have a string in the form category:accountName that you can use to get the name to compare with the session.

更多推荐

本文发布于:2023-07-31 18:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1347267.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项   流星   元素   事件   element

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!