Что касается моей таблицы связывания нужно преобразовать этот JSON объект:Создание объекта с динамическим массивом
{"id":"txn_18Ptu52eZvKYlo2C9c8ejhap","amount":999,"availableOn":1467331200,"created":1466773164,"currency":"usd"}
во что-то вроде этого:
{"data":[{"id":"txn_18Ptu52eZvKYlo2C9c8ejhap","amount":999,"availableOn":1467331200,"created":1466773164,"currency":"usd"}]}
Я попробовал этот один:
success : function(data1, textStatus, jqXHR) {
var resp = [data1];
var response = {data: resp};
var oJSonModel = new sap.ui.model.json.JSONModel(response);
this.getView().setModel(oJSonModel);
data1 - это объект, который мы получаем выше, затем я сохранил его в массиве, который называется resp, а затем я попытался сохранить его в новом объект, но это пошло не так, я думаю, потому что кажется, что я сохранил только вторую запись этого массива, потому что мой отладчик показал мне это:
response = Object {data: Array[1]}
, а затем, конечно, мое связывание не работает .... .
Edit здесь мой полный код:
sap.ui.define([
'sap/ui/core/mvc/Controller',
'sap/m/MessageToast',
'somepath/balance/model/formatter'
], function(Controller, MessageToast, formatter) {
"use strict";
return Controller.extend("somepath.balance.controller.Balance", {
formatter: formatter,
onInit: function() {
this.getView().setModel(new sap.ui.model.json.JSONModel());
},
onTransactionList: function() {
this.getView().getModel().loadData("/balance/retrieveTransacationList?limit=" + this.getView().byId("quantity").getValue());
},
onTransactionByTransactionId: function() {
var that = this;
jQuery.ajax({
type: "GET",
contentType: "application/json",
url: "/balance/retrieveTransaction?transactionId=" + that.getView().byId("searchById").getValue(),
processData: true,
dataType: "text",
async: false,
success: function(data1, textStatus, jqXHR) {
var resp = [];
resp.push(data1);
var response = {
data: resp[0]
};
var oJSonModel = new sap.ui.model.json.JSONModel(response);
that.getView.setModel(oJSonModel);
},
error: function(jqXHR, textStatus, errorThrown) {
var sErrorText = "" + jqXHR.status + " - " + errorThrown + " - " + jqXHR.responseText;
MessageToast.show(sErrorText);
}
});
}
});
});
мой стол, на мой взгляд:
<t:Table id="transactionUiTable"
columnHeaderVisible="true"
selectionMode="Single"
selectionBehavior="RowSelector"
enableColumnReordering="false"
enableGrouping="false"
showColumnVisibilityMenu="false"
enableSelectAll="false"
enableCustomFilter="false"
enableBusyIndicator="false"
rows="{path: '/data'}"
rowSelectionChange="onTableSelectionChange">
<t:toolbar>
<Toolbar id="toolbar">
<Input width="15%" id="searchById" value=""/>
<Button text="{i18n>searchTransaction}" type="Emphasized" icon="sap-icon://search" press="onTransactionByTransactionId"/>
<Button text="{i18n>customerTransactionlist}" type="Emphasized" icon="sap-icon://search" press="onCustomerTransactionList"/>
<ToolbarSpacer/>
<Input width="5%" id="quantity" value=""/>
<Button text="{i18n>transactionList}" type="Unstyled" press="onTransactionList"/>
<Button icon="sap-icon://action-settings" type="Default"/>
</Toolbar>
</t:toolbar>
<t:columns>
<t:Column id="Id" hAlign="Center">
<Label id="labelId" text="{i18n>transactionId}"/>
<t:template>
<Text text="{id}"/>
</t:template>
</t:Column>
<t:Column id="columnDatetime" hAlign="Center">
<Label id="labelDatetime" text="{i18n>datetime}"/>
<t:template>
<Text text="{parts: [
{path: 'created'}
],
formatter : '.formatter.date'}"/>
</t:template>
</t:Column>
<t:Column id="columnAmount" hAlign="Center">
<Label id="labelAmount" text="{i18n>amount}"/>
<t:template>
<Text text="{
parts: [
{path: 'amount'},
{path: 'currency'}
],
type: 'sap.ui.model.type.Currency',
formatOptions: {
showMeasure: false}}"/>
</t:template>
</t:Column>
<t:Column id="columnCurrency" hAlign="Center">
<Label id="labelCurrency" text="{i18n>currency}"/>
<t:template>
<Text text="{currency}"/>
</t:template>
</t:Column>
<t:Column id="columnFee" hAlign="Center">
<Label id="labelFee" text="{i18n>fee}"/>
<t:template>
<Text text="{
parts: [
{path: 'fee'},
{path: 'currency'}
],
type: 'sap.ui.model.type.Currency',
formatOptions: {
showMeasure: false}}"/>
</t:template>
</t:Column>
<t:Column id="columnNet" hAlign="Center">
<Label id="labelNet" text="{i18n>net}"/>
<t:template>
<Text text="{
parts: [
{path: 'net'},
{path: 'currency'}
],
type: 'sap.ui.model.type.Currency',
formatOptions: {
showMeasure: false}}"/>
</t:template>
</t:Column>
<t:Column id="columnType" hAlign="Center">
<Label id="labelType" text="{i18n>type}"/>
<t:template>
<Text text="{type}"/>
</t:template>
</t:Column>
<t:Column id="columnStatus" hAlign="Center">
<Label id="labelStatus" text="{i18n>status}"/>
<t:template>
<Text text="{status}"/>
</t:template>
</t:Column>
</t:columns>
</t:Table>
'obj.data [0]' должна работать. – Tushar
1 в 'Array [1]' это длина. а не индекс. – BenG
спасибо, что сработал, но у меня появились проблемы с моим JsonModel, потому что я получаю эту ошибку: sap-ui-core.js: 71 Uncaught TypeError: Не удается прочитать свойство 'setModel' неопределенного – Nali