角色2:我如何获得该数组的值?

时间:2018-04-23 22:25:03

标签: angular

现在我尝试获取此数组的值ScreenShot

我试图用

获得该值
var L = e.Lookups

var L = e['Lookups']

但是当我试图获得那个数组时,该对象总是返回undefined。

有什么建议吗?

感谢您的帮助。

更新:

Screenshot 2

代码: 在这个方法中,我收到一个对象数组, 在调试模式下直接访问位置5,并且出现未定义的值

getQuestions(template: any) {
console.log('template: ', template)
console.log('1-template 5: ', template[5].Lookups);
console.log('2-template 5: ', template[5]['Lookups']);
var questions: QuestionBase<any>[] = [];

if(template !== undefined && template !== null) {
  template.forEach(e => {

      // Getting Lookups
      switch(e.SimpleDataType){
        case 'Number':
              questions.push(
                new TextboxQuestion({
                  Field: e.Field,
                  Label: e.Label,
                  Required: e.Required,
                  type: e.SimpleDataType,
                  ACL: e.ACL,
                  value: e.value  || ''
                })
              );
        break;

        case 'Int':
              questions.push(
                new TextboxQuestion({
                  Field: e.Field,
                  Label: e.Label,
                  Required: e.Required,
                  type: 'Number',
                  ACL: e.ACL,
                  value: e.value  || ''
                })
              );
        break;

        case 'String':
              questions.push(
                new TextboxQuestion({
                  Field: e.Field,
                  Label: e.Label,
                  Required: e.Required,
                  Hidden : e.Hidden,
                  SimpleDataType: 'String',
                  ACL: e.ACL,
                  value: e.value  || ''
                })
              );
        break;

        case 'Character':
              questions.push(
                new TextboxQuestion({
                  Field: e.Field,
                  Label: e.Label,
                  Required: e.Required,
                  Hidden : e.Hidden,
                  SimpleDataType: 'String',
                  type: 'String',
                  ACL: e.ACL,
                  value: e.value  || ''
                })
              );
        break;
        case 'String List, Single':
              questions.push(
                new DropdownQuestion({
                  Field: e.Field,
                  Label: e.Label,
                  Required: e.Required,
                  Hidden : e.Hidden,
                  type: 'String List, Single',
                  SimpleDataType: 'List',
                  options: e.Lookups,
                  ACL: e.ACL,
                  value: e.value || ''
              }));
        break;

        case 'String List, Multi':
          let v = [ ];
          v.push(e.value);
              questions.push(
                new DropdownQuestion({
                  Field: e.Field,
                  Label: e.Label,
                  Required: e.Required,
                  Hidden : e.Hidden,
                  type: 'String List, Multi',
                  SimpleDataType: 'List',
                  options: e.Lookups,
                  ACL: e.ACL,
                  value: v || []
              }));
        break;

        case 'Boolean':
              questions.push(
                new CheckboxControl({
                  Field: e.Field,
                  Label: e.Label,
                  type: 'Boolean',
                  Required: e.Required,
                  Hidden : e.Hidden,
                  ACL: e.ACL,
                  value: e.value
                })
              );

        break;

        case 'Date':
              questions.push(
                new DateQuestion({
                  Field: e.Field,
                  Label: e.Label,
                  type: 'Date',
                  Required: e.Required,
                  Hidden : e.Hidden,
                  SimpleDataType: 'Date',
                  ACL: e.ACL,
                  value: e.value  || ''
                })
              );
        break;


        case 'Timestamp':
          questions.push(
            new DateQuestion({
              Field: e.Field,
              Label: e.Label,
              type: 'Date',
              Required: e.Required,
              Hidden : e.Hidden,
              SimpleDataType: 'Date',
              ACL: e.ACL,
              value: e.value || ''
            })
          );
          break;
      }

    });
    // Field input type=File
          questions.push(
            new FileQuestion({
              Field: "File",
              Label: "Upload Image",
              Required: false,
              type: "file",
              ACL: 1
            })
          );
    return questions.sort((a, b) => a.order - b.order);
  }
}

1 个答案:

答案 0 :(得分:0)

试试这个:

getQuestions(template: any) {
  template = [...template];
  ...
}