跟踪器重新计算功能(不变违规)的例外情况

时间:2017-05-24 11:47:37

标签: reactjs meteor meteor-accounts

我无法解释的奇怪行为:
这是一个反应组件,显示一个字符串化的对象 - 来自谷歌帐户的数据。 enter image description here
enter image description here

如果我将 props.user[0].services 更改为
props.user[0].services.google 属性
enter image description here 我收到错误

enter image description here

1 个答案:

答案 0 :(得分:1)

可能是函数调用后加载了services属性。

我解决这个问题的方法是使用lodash来获取默认属性。它还可以防止引用错误:

DECLARE @SampleData AS TABLE
(
    Value1 int,
    Value2 varchar(20)
)

INSERT INTO @SampleData
VALUES
(1, 'A'),    
(1, 'B'),    
(2, 'A'),     
(2, 'B'),     
(2, 'C'),     
(3, 'A'),      
(3, 'B'),
(4, 'A'),
(4, 'C'),
(5, 'B'),
(5, 'A'),
(6, 'C'), 
(7, 'B'), 
(8, 'B'),
(9, 'A')

;WITH temp AS
(
    SELECT sd.Value1, 
         stuff((    SELECT ','+ sd2.Value2
                FROM @SampleData sd2
                WHERE sd2.Value1 = sd.Value1    
                ORDER BY sd2.Value2 -- Value2 must be ordered to compare exactly.
                FOR XML PATH('')
              )
                   ,1,1,'') as Value2 
    FROM 
    (
       SELECT DISTINCT sd.Value1
       FROM @SampleData sd
    ) sd
)
SELECT t.Value1, STUFF((
                       SELECT ',' + CAST(t2.Value1 AS varchar(10))
                       FROM temp t2
                       WHERE     t2.Value2 = t.Value2 
                             AND t2.Value1 != t.Value1
                       ORDER BY t2.Value1                       
                       FOR XML PATH ('')
                    )
                    ,1,1,'') as Value2
FROM temp t