http://jsfiddle.net/VqenG/多對象淘汰賽映射
希望能有些knockout.js大師可以擺脫這個
我試圖讓聯繫對象進入接觸觀察到的陣列,它本身就是內可觀察到的陣列的一些光ContactGroup對象,但我不明白如何做到這一點?這是可能的,還是我以錯誤的方式接近它?謝謝!
var json =
{"contactGroups" : [
{
"name" : "Contact Group",
"contact" : [
{
"name" : "aaaa",
"email" : "",
"telephone" : "",
"mobile" : "",
"mail_group" : "",
"comment" : ""
},
{
"name" : "bbbb",
"email" : "",
"telephone" : "",
"mobile" : "",
"mail_group" : "",
"comment" : ""
},
{
"name" : "cccc",
"email" : "",
"telephone" : "",
"mobile" : "",
"mail_group" : "",
"comment" : ""
}
]
}
]}
function TechnicalViewModel(){
self = this;
var ContactGroups = ko.utils.arrayMap(json.contactGroups, function(item) {
var group = new ContactGroup(item);
var contacts = ko.utils.arrayMap(item.contact, function(item) {
return new Contact(item)
});
group.contact(contacts)
return group;
})
self.contactGroups(ContactGroups)
function ContactGroup(data){
var self = this;
self.name = ko.observable(data.name);
self.contact = ko.observableArray([]);
function Contact(data){
this.name = ko.observable(data.name);
this.email = ko.observable(data.email);
this.telephone = ko.observable(data.telephone);
this.mobile = ko.observable(data.mobile);
this.mail_group = ko.observable(data.mail_group);
this.comment = ko.observable(data.comment);
}
}
}
TechnicalView = new TechnicalViewModel
ko.applyBindings(TechnicalView);
非常感謝!需要刷上我的範圍! – Wellso