0
由於我的模型的一部分,我有這個類打字稿:填充類[]用JSON在打字稿
module App.Model {
export class Unit {
id: number;
participantId: number;
name: string;
isProp: boolean;
}
}
在控制器中,我需要用id
AA哈希關鍵:
module App.Controllers {
export class MyController {
public units: App.Model.Unit[];
populateDemoData() {
this.units = {
"1": { "id": 1, "participantId": 1, "name": "Testname", "isProp": true },
"2": { "id": 2, "participantId": 1, "name": "Another name", "isProp": false }
};
}
}
}
然而,編譯器,我得到了以下錯誤消息:
Error 2 Cannot convert '{ }; [n: number]: App.Model.Unit; }' to ' }; [n: number]: App.Model.Unit; }' is missing property 'concat' from type 'App.Model.Unit[]'.
我在做什麼錯了嗎?爲什麼TypeScript要求concat
屬性?
感謝您的回答。我如何將單位定義爲散列?我的意思是哈希!我正在玩這個定義,原來是'units:App.Model.Unit []'產生了同樣的錯誤。我更新了這個問題,對不起! –
好吧,我編輯了我的答案,我希望這有助於。 – thoughtrepo
看起來不錯,謝謝。我今晚會在網上查詢 –