2016-04-06 74 views
0

所以像在標題中我有一個序列化組合對象的問題。aurelia可綁定對象屬性未在json中序列化

類「度假村」有兩個bindalbe屬性:地址和管理器。兩者都沒有被httpClient.json序列化,但是如果刪除@bindable - 序列化工作完美。問題在哪裏?

import {bindable} from 'aurelia-framework'; 
import {Address} from './../models/address.js' 
import {Employee} from './../models/employee.js' 

export class Resort { 
    id = ""; 
    name=""; 
    category_id = ""; 
    organization_id = ""; 
    manager_id = ""; 
    owner_id = ""; 
    active = ""; 
    deleted = ""; 
    date_created = ""; 
    date_modified = ""; 
    checkin = ""; 
    checkout = ""; 
    date_deleted = ""; 
    notes = ""; 
    address_id = ""; 

    @bindable address = new Address(); 
    @bindable manager = new Employee(); 

    category_attraction = []; 
    category_option = []; 
} 

這是我取代碼:

this.http.fetch('resorts', { 
      method: 'post', 
      body: json(resortObject) 
     }) 

JSON功能結果:

{"id":"","name":"LOLO","category_id":"","organization_id":"","manager_id":"","owner_id":"","active":"","deleted":"","date_created":"","date_modified":"","checkin":"","checkout":"","date_deleted":"","notes":"","address_id":"","category_attraction":[],"category_option":[]} 

TIA :)

+0

據我所知,應該在Web組件類中使用@bindable屬性。在我看來,如果你的類是一個Web組件,你不應該把它發佈到你的服務器上,你應該把它轉換成一個普通的javascript對象。想象一下,如果你的類有一些屬性和功能,這對於處理狀態和事件是必需的。您不希望將所有這些不必要的信息發送到服務器。 –

回答

1

這是因爲這些屬性已被封裝爲屬性getter/setter並且不再可枚舉。

0

我不知道你爲什麼有這種行爲,但您可以嘗試使用JSON.serialize(resortObject)而不是json(resortObject)

相關問題