Sé cómo enlazar a una propiedad, pero lo hacen como me ato a una propiedad como: Parent.ChildKnockout.js como me se unen a una sub propiedad
Usando el ejemplo hola mundo en Knockout JS. com: HTML:
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>
<h2>ChildProperty: <span data-bind="text: parentProperty.childProperty"> </span>!</h2>
Javascript:
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.parentProperty = ko.observable(
{
childProperty: "I am a child Property"
});
this.fullName = ko.computed(function() {
// Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
return this.firstName() + " " + this.lastName();
}, this);
};
ko.applyBindings(new ViewModel("Planet", "Earth"));
me gustaría crear una unión a la childProperty.
he creado un jsfiddle here
Gracias
Gracias Tim! ¿Cómo no pensé en probar esto? – Andre
Esta respuesta me ayudó en un problema vagamente relacionado. ¡Gracias! –
ahh! ¿Dónde está esto en los documentos knockout por cierto? No pude verlo –