Skip to Content
0

Set API Service in JsonDataMOdel

Mar 26 at 12:15 PM

25

avatar image

Hi Guys,

My access attempt is my table in two ways:

That:

    var myHeaders = new Headers();
      myHeaders.append(
        "Access-Control-Allow-Origin", "*",
        "Access-Control-Allow-Headers", "*",
        "content-type", "text/json"
    );


    var oModel = new sap.ui.model.json.JSONModel();
    oModel.loadData("http://localhost:28750/api/Employee", myHeaders);
    console.log(oModel);





 var oTable = new sap.m.Table();
    oTable.addColumn(new sap.m.Column({
       header: new sap.m.Label({text:"ID"}),
    }));
    oTable.addColumn(new sap.m.Column({
       header: new sap.m.Label({text:"Nome"}),
    }));
    oTable.addColumn(new sap.m.Column({
       header: new sap.m.Label({text:"Sobrenome"}),
    }));
    oTable.addColumn(new sap.m.Column({
       header: new sap.m.Label({text:"Office"}),
    }));
    oTable.addColumn(new sap.m.Column({
       header: new sap.m.Label({text:"Posicao"}),
    }));
    oTable.addColumn(new sap.m.Column({
       header: new sap.m.Label({text:"Excluir"}),
    }));
    oTable.addColumn(new sap.m.Column({
       header: new sap.m.Label({text:"Editar"}),
    }));
    oTable.addColumn(new sap.m.Column({
       header: new sap.m.Label({text:"Ver"}),
    }));
    var oTemplate = new sap.m.ColumnListItem({
		type: sap.m.ListType.Active,
		cells : [
			new sap.m.Label({
                 text : "{EmpCode}"
			}),
			new sap.m.Label({
                 text: "{EmployeeID}"
			}),


			new sap.m.Label({
                 text: "{FirstName}"
			}),
			new sap.m.Label({
                 text: "{LastName}"
			}),
      new sap.m.Label({
                 text: "{Office}"
      }),
      new sap.m.Label({
                 text: "{Position}"
      }),
      new sap.m.Button({
            icon : "sap-icon://sys-cancel",
                press : function(evt) {
                  console.log("press")
                        $.proxy(oController.MsgAlert(),oController)
                          if (evt.getSource().getParent().getParent().getItems().length > 0) {
                                row = evt.getSource().getParent().getId();
                            evt.getSource().getParent().getParent().removeItem(row);                 
                    			}
                  		 } 
                	}),
               new sap.m.Button({
               		icon: "sap-icon://accounting-document-verification",
               		press: function(event){
               			//console.log("funcionou");
               			id = event.getSource().getParent().getId()
               			$.proxy(oController.editTicket(id), oController);
               		}
               })
		]
	});
  oTable.setModel(oModel);
  oTable.bindAggregation("items","/",oTemplate);
  var components = [oTable];
	return components;






and That:

In my view:

    var DataObject = $.proxy(oController.GetEmployees());
    var oModel = new sap.ui.model.json.JSONModel(DataObject);

In my Controller

		var myHeaders = new Headers();
		myHeaders.append(
			"Access-Control-Allow-Origin", "*",
			"Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, GET",
			"Content-Type","application/json"
			);
		var myInit = { 
			   method: 'GET',
               headers: myHeaders,
               mode: 'no-cors',
               dataType: "text"
           };


		fetch("http://localhost:28750/api/employee", myInit, {
		    headers: myHeaders
		}).then(function(response) {
			console.log(200);
		    return response;
		}).then(function (json) {
		    console.log(json);
		    //console.log("funcionou!")
		});

None of them brings results on my table =/

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

p1940199606 trial Mar 26 at 02:50 PM
0

Hello Gabriel,

Try running chrome with --args --disable-web-security to rule out CORS. Also, Access-Control-Allow-Headers being a response header, try with Access-Control-Request-Headers. See if that helps.

Thanks,

Rajit

Share
10 |10000 characters needed characters left characters exceeded