Web サービスから返された複雑な json をグリッドに入力したいと考えています。私のjsonには2つのものが含まれています:
- data: グリッドを埋めるレコードの配列
- 列: グリッドの構成 (レイアウト) を持つ配列
schema.data を指定して、グリッドに「データ」を正常に入力しました。
私の問題は、グリッド構成 (レイアウト) にあります。requestEnd
データソースのイベントで列配列を取得し、それをcustomersSource
(データソース) に追加して、gridOptions でアクセスできるようにします。
問題は、オブジェクトをログに記録すると、追加した cols 配列がそこにあり、設定されていないcustomersSource
適切なデータで満たされていることがわかります。$scope.mainGridOptions.columns
customersSource.cols
これは、非同期に設定されているという事実に関係していると思いますが、customersSource.cols
角度がデータバインディングでこれを処理するべきではありませんか?
また、 Data source vs. Angularを読みましたが、何かを Observable として設定する必要があるかもしれませんが、正確に何をすべきか混乱しています。
どうすればこれを修正できますか?
これが私のコードです:
var customersSource = new kendo.data.DataSource({
transport: {
read: {
url: "http://....",
dataType: "json"
}
},
schema: {
data: "data"
},
requestEnd: function (e) {
this.cols = e.response.columns;
}
});
$scope.mainGridOptions = {
dataSource: customersSource, // OK
columns: customersDataSource.cols, // undefined - uses default
height: 500,
scrollable: true,
selectable: true
};
これが私のJSONです
{
"data": [
{
"id": 0,
"firstname": "Dalton",
"lastname": "Holden",
"gender": "male",
"email": "daltonholden@tellifly.com",
"phone": "871-407-2973",
"address": "22 National Drive, Brenton, Louisiana",
"birthday": "21/04/1965",
"currency": "GBP"
},
{
"id": 1,
"firstname": "Allyson",
"lastname": "Odom",
"gender": "female",
"email": "allysonodom@tellifly.com",
"phone": "922-548-2725",
"address": "44 Quincy Street, Thynedale, Georgia",
"birthday": "28/08/1961",
"currency": "CHF"
},
{
"id": 2,
"firstname": "Sweet",
"lastname": "Branch",
"gender": "male",
"email": "sweetbranch@tellifly.com",
"phone": "880-593-2244",
"address": "81 Fenimore Street, Veguita, Missouri",
"birthday": "08/08/1953",
"currency": "AUD"
}
],
"columns": [
{
"field": "firstname",
"title": "Frist Name",
"width": 200,
"attributes": {
"class": "",
"style": "text-align: left;"
},
"headerAttributes": {
"class": "table-header-cell",
"style": "text-align: left;"
}
},
{
"field": "lastname",
"title": "Last Name",
"attributes": {
"class": "",
"style": "text-align: left;"
},
"headerAttributes": {
"class": "table-header-cell",
"style": "text-align: left;"
}
},
{
"field": "gender",
"title": "Gender",
"attributes": {
"class": "",
"style": "text-align: left;"
},
"headerAttributes": {
"class": "table-header-cell",
"style": "text-align: left;"
}
},
{
"field": "email",
"title": "e-mail",
"attributes": {
"class": "",
"style": "text-align: left;"
},
"headerAttributes": {
"class": "table-header-cell",
"style": "text-align: left;"
}
},
{
"field": "phone",
"title": "Phone Number",
"attributes": {
"class": "",
"style": "text-align: right;"
},
"headerAttributes": {
"class": "table-header-cell",
"style": "text-align: right;"
}
},
{
"field": "address",
"title": "Address",
"attributes": {
"class": "",
"style": "text-align: left;"
},
"headerAttributes": {
"class": "table-header-cell",
"style": "text-align: left;"
}
},
{
"field": "birthday",
"title": "Birthday",
"attributes": {
"class": "",
"style": "text-align: center;"
},
"headerAttributes": {
"class": "table-header-cell",
"style": "text-align: center;"
}
},
{
"field": "currency",
"title": "Currency",
"attributes": {
"class": "",
"style": "text-align: center;"
},
"headerAttributes": {
"class": "table-header-cell",
"style": "text-align: center;"
}
}
]
}
編集 テスト プロジェクトのプランカーを作成しました。ご覧のとおり、グリッドを埋めることができますが、mainGridOptions.columns に問題があります。どんな助けでも大歓迎です! http://plnkr.co/edit/5pjFQGkgTivqVkxsFBse