简体   繁体   English

处理空异常构成Rally数据存储

[英]Handling null exceptions form a Rally Data store

I am stuck on how to handle the null exception with a nested object in null in the result. 我被困在如何使用null中的嵌套对象处理结果中的null异常。 I am returning these values to a grid. 我将这些值返回到网格。

Example is the Iteration. 示例是迭代。 I need to get the name property of the iteration object. 我需要获取迭代对象的name属性。

    _onDataLoaded: function(store, data){
                var stories = [];

                _.each(data, function(story) {
                            var s  = {
                                FormattedID: story.get('FormattedID'),
                                Name: story.get('Name'),
                                Project: story.get('Project').Name,
                                ScheduleState: story.get('ScheduleState'),
                                TaskRemainingTotal: story.get('TaskRemainingTotal'),
                                Blocked: story.get('Blocked'),
                                Iteration: story.get('Iteration').Name,
                                Release: story.get('Release').Name,
                                Predecessor: []
                            };

                            var predecessors = story.getCollection('Predecessors', {

                     fetch:['Rank','FormattedID','Name','Predecessors','Successors','Project','ScheduleState','FormattedID','Blocked','Iteration','Release','TaskRemainingTotal']});
                            predecessors.load({
                                callback: function(records, operation, success){
                                    _.each(records, function(predecessors){
                                        s.Predecessor.push({Predecessorformatid: predecessors.get('FormattedID'),
                                                        PredecessorsBlocked: predecessors.get('Blocked'),
                                                        Predecessorteam: predecessors.get('Project').Name,
                                                        PredecessorsState: predecessors.get('ScheduleState'),
                                                        PredecessorsTaskActualTotal: predecessors.get('TaskRemainingTotal'),
                                                        PredecessorsIteration: predecessors.get('Iteration').Name,
                                                        PredecessorsRelease: predecessors.get('Release').Name,
                                                        Predecessorname: predecessors.get('Name')

                                                    });
                                    }, this);

                                    this._createGrid(stories);
                                },
                                scope: this
                            });
                            stories.push(s);
                }, this);

I usually do something like this if there is a chance of null: 如果有可能出现空值,我通常会执行以下操作:

var iterationName = story.get('Iteration') && story.get('Iteration').Name;

That works because if the left hand side of the && operator is falsy (which null is) then the operator will short circuit and not evaluate the right hand side. 之所以可行,是因为如果&&运算符的左侧是虚假的(该值为null),那么该运算符将短路并且不评估右侧。 If the left hand side is truthy then it will evaluate and return the right hand side. 如果左侧是真实的,则它将求值并返回右侧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM