这应该是一个简单的:我的viewmodel中有一个名为“To”的observableArray对象,它包含EmailAddress元素。每个元素都有两个属性:DisplayName和Address。
我想将数组中的每个元素打印到单个输入字段,半冒号分隔。我现在得到的是:
“[object Object],[object Object]”
如何绑定和打印属性?我尝试了各种解决方案,例如添加“value:to.DisplayName”,但无济于事。
<!-- illustration only, this is what the items in the TO array look like
I want to print the value of DisplayName for each element -->
var EmailAddress = function(dName, addr) {
self = this;
self.DisplayName = dName;
self.Address = addr;
};
<!-- viewmodel -->
var EmailModel = function (email) {
var self = this;
self.id = ko.observable();
self.subject = ko.observable();
self.body = ko.observable();
self.from = ko.observable();
self.to = ko.observableArray(); <-- display the DisplayName property of these elements)
self.cc = ko.isObservable();
self.bcc = ko.observable();
};
<!-- print the contents of the TO array -->
<input data-bind="value: to" type="text" />