2
이것은 간단해야합니다. EmailAddress 요소가 포함 된 내 viewmodel에 "To"라는 observableArray 객체가 있습니다. 각 요소에는 DisplayName과 Address의 두 가지 속성이 있습니다.KnockoutJS - observableArray의 내용을 텍스트 상자에 쉼표로 구분하여 표시합니다.
배열의 각 요소를 단일 입력 필드에 인쇄하려는 경우 세미콜론으로 구분합니다. 내가 지금 무엇입니까 것은 :
"[개체 개체], [개체 개체]"
가 어떻게 결합 않고 대신 속성을 인쇄? "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" />
덕분에, 그러나 그것은 나에게 그냥 "값 님"을 사용할 때와 동일한 출력을 제공합니다. 내 ObservableArray 개체가 아니라 문자열을 차이가 있기 때문에 나는뿐만 아니라 질문을 업데이트했습니다. – Andreas
@Andreas 편집보기 – Tyrsius
좋아, 그거야! 고맙습니다. 계산 된 함수를 피하고 속성에 직접 액세스하는 것이 좋겠지 만 이것이 가능할 것입니다. – Andreas