この配列を観測可能な配列にマップする必要があります。KnockoutJS - 多次元配列のマップ
actionsDataTime = {
"t16082209": [
{
"timeId": "16082209",
"id": 176,
"class_from": "09:00",
"class_to": "10:25",
"action": {
"name": "AQUA",
"color": "aqua",
"icon": ""
},
"trainer": {
"id": 348,
"name": "Art Edition"
},
"capacity": 11,
"capacity_left": 11,
"substitutes": 5,
"substitutes_left": 5,
"price": 1
}
],
"t16082308": [
{
"timeId": "16082308",
"id": 169,
"class_from": "08:00",
"class_to": "09:00",
"action": {
"name": "ZUMBA",
"color": "zumba",
"icon": ""
},
"trainer": {
"id": 210,
"name": "Adam Pt\u00e1\u010dek"
},
"capacity": 10,
"capacity_left": 10,
"substitutes": 5,
"substitutes_left": 5,
"price": 1
}
],
"t16082408": [
{
"timeId": "16082408",
"id": 173,
"class_from": "08:00",
"class_to": "09:05",
"action": {
"name": "KICK BOX",
"color": "box",
"icon": ""
},
"trainer": {
"id": 360,
"name": "Alexandra Galov\u00e1"
},
"capacity": 10,
"capacity_left": 10,
"substitutes": 5,
"substitutes_left": 5,
"price": 2
},
{
"timeId": "16082408",
"id": 175,
"class_from": "08:00",
"class_to": "09:05",
"action": {
"name": "KICK BOX",
"color": "box",
"icon": ""
},
"trainer": {
"id": 360,
"name": "Alexandra Galov\u00e1"
},
"capacity": 10,
"capacity_left": 10,
"substitutes": 5,
"substitutes_left": 5,
"price": 2
}
]
}
セクション「t16082308」は、アプリケーションに必要なタイムスタンプの1つで、動的です。配列内のアクションの数も変更できます。
私はマッピングモジュールによって、このように、これをマッピングすることができる午前
ko.mapping.fromJS(actionsDataTime, self.actionsData);
しかし、私はこの
self.reloadActions = function() {
$.ajax({
type: 'GET',
url: {link reloadActions! },
dataType: "json",
success: function(data) {
ko.mapping.fromJS(data, {}, self.actionsData);
}
})
};
のように、サーバーからそれをリロードする必要があり、新しいタイムスタンプセクションまたは新しいソーマがあった場合にアクション - フロントエンドで何も変わらず、すべてが観測可能なものとしてマッピングされているわけではありません。私は "容量"のようないくつかの値を変更するだけでうまくいきます。
アクションを追加または削除したときに変更が表示されるように、どうすればよいでしょうか?