我有一个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.
更多推荐
发布评论