把手在自定义助手中使用@root

时间:2017-02-23 00:47:14

标签: handlebars.js

我有一个场景,我试图从嵌套的for循环中访问自定义帮助器中的单独元素。当我在for循环之外使用root时,我没有任何问题,但我似乎无法在我的自定义助手中使用@root。我想也许../会起作用,但似乎只是向上移动到父元素,而不是单独的元素

以下是我的两个对象:

category //Object being looped through
categoryQuery //Query object being compared to looped values

以下是我的观点(循环显示ID'然后将所选内容应用于附加到categoryQuery的ID:

{{#category}}
   <option value="{{this.categoryId}}"{{selected this.categoryId @root.categoryQuery}}>{{this.categoryName}}</option>
{{/category}}

如果值匹配,则为预选值:

/Preselect option value that is associated with edited record
    hbs.registerHelper('selected', function(option, value){
        if (option === value) {
            return 'selected';
        } else {
            return '';
        }
    });

已更新:

console.log('Option : ' + option + ' Value : ' + value);添加到我的注册帮助者的else语句中时,我会收到以下信息,表明@root.category不是Option : 1 Value : 2 Option : 2 Value : 2 Option : 1 Value : undefined 不是问题拉入值,但它没有正确等同。

例如:

#legacySQL
SELECT
  provider, title, revenue
FROM  
-- Top 2 (alphabetically) Titles for each of Top 3 Providers 
( 
SELECT
  titles.provider AS provider,
  titles.title AS title,
  titles.revenue AS revenue,
  top_providers.revenue AS pos
FROM (
  SELECT provider, title, revenue, ROW_NUMBER() OVER(PARTITION BY provider ORDER BY title) AS pos 
  FROM (
    SELECT provider, title, SUM(customer_price) AS revenue 
    FROM [integrated-myth-156821:fintest.m10]
    GROUP BY provider, title
  )
) AS titles
JOIN (
  SELECT
    provider,
    SUM(customer_price) AS revenue
  FROM [integrated-myth-156821:fintest.m10]
  GROUP BY provider
  ORDER BY revenue DESC  
  LIMIT 3 -- sets top 3 providers
) top_providers 
ON top_providers.provider = titles.provider
WHERE pos < 3 -- set top two titles
),
-- Top 3 Providers by Revenue
( 
  SELECT
    provider,
    '' AS title,
    SUM(customer_price) AS revenue,
    SUM(customer_price) AS pos
  FROM [integrated-myth-156821:fintest.m10]
  GROUP BY provider
  ORDER BY revenue DESC  
  LIMIT 3 -- sets top 3 providers
)
ORDER BY pos DESC, provider, title  

1 个答案:

答案 0 :(得分:0)

我确定问题的根本原因是比较运算符的严格性。更改为==后,我能够正确识别匹配的ID