gpt4 book ai didi

javascript - 处理 Rally 数据存储中的空异常

转载 作者:行者123 更新时间:2023-11-28 06:37:04 26 4
gpt4 key购买 nike

我陷入了如何使用结果中 null 中的嵌套对象来处理 null 异常的问题。我将这些值返回到网格。

示例是迭代。我需要获取迭代对象的 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);

最佳答案

如果有可能为空,我通常会这样做:

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

这是有效的,因为如果 && 运算符的左侧为假(即 null),那么该运算符将短路并且不会评估右侧。如果左侧为真,那么它将评估并返回右侧。

关于javascript - 处理 Rally 数据存储中的空异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34183757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com