Ho un semplice foreach:knockout proprietà viewmodel indefinito
<div id="customersArea" data-bind="foreach: people">
<div class="section" data-bind="attr: { 'personid': PersonId }" >
<div class="sectionActions">
<div><a class="action" href="#" data-bind='click: $parent.removePerson'>Remove</a></div>
</div>
<div class="sectionText">
<span data-bind="if:LastName, text:LastName"></span>
<span data-bind="if:FirstName, text:FirstName"></span>
<span data-bind="if:MailingAddress">
<span data-bind="with:MailingAddress">
<span data-bind="text:StreetPartOne"> </span>
<span data-bind="text:StreetPartTwo"> </span>
<span data-bind="text:City"></span>
<span data-bind="text:PostalCode"></span>
</span>
</span>
<span data-bind="if:EmailAddress, text:EmailAddress"></span>
<span data-bind="if:MainPhoneNumber, text:MainPhoneNumber"></span>
<span data-bind="if:MobilePhoneNumber, text:MobilePhoneNumber"></span>
</div>
<div class="sectionOptions">
</div>
</div>
</div>
Sto cercando di renderlo tale che io possa legare contro un modello {PersonId: 33} e il resto sarà solo non rende se mancante. quando provo in questo e in altri modi ottengo
Uncaught Error: Unable to parse bindings.
Message: ReferenceError: MailingAddress is not defined;
Bindings value: if:MailingAddress
ho creato un semplice jsfiddle alla prova:
ho provato testo con init con {PersonId: 33, Cognome: "Frank"} e doesn 't mostrare il cognome ... – maxfridbe
Ho aggiornato la rilegatura. Devi essere leggermente diverso per il binding 'text': http://jsfiddle.net/rniemeyer/dLCL8/4/ –
@RPNiemeyer Grazie per il suggerimento, come possiamo farlo con" attr "binding? –