2012-05-18 12 views
61

no puedo ver lo que está mal aquí, pero la imagen no se visualiza mediante la plantilla siguiente golpe de gracia:plantilla Knockout utilizando datos se unen a la propiedad de imagen src no trabajar

<script type="text/html" id="legend-template">  
    <div><input type="checkbox" data-bind="click : doSomething" ></input> 
     <img width="16px" height="16px" data-bind="src: 'imagePath'" />   
     <span data-bind="text : label"> </span> 
    </div>   
</script> 

El objeto de este está siendo obligado a PARECE esto:

tut.myObject= function (imagePath, label) { 
    this.label = ko.observable(label); 
    this.imagePath = ko.observable(imagePath || liveString + '/Content/images/marker.png'); 
}; 

tut.myObject.prototype = { 
    doSomething: function() { alert("do what?"); 
    } 
}; 

Cuando el objeto HTML es interpretado veo la etiqueta y haciendo clic en la casilla invoca doSomething.

TIA.

Respuesta

150

Solo algunos atributos se pueden enlazar directamente; intente usar attr - le permitirá establecer cualquier atributo en un elemento.

<img width="16px" height="16px" data-bind="attr:{src: imagePath}" /> 
+0

Gracias por responder PERO cuando me da el siguiente error: Error de tiempo de ejecución de Microsoft JScript: no se pueden analizar los enlaces. Mensaje: SyntaxError: esperado ':'; Valor de enlaces: attr {src: imagePath} –

+0

Entendido, gracias. Debería ser

+22

disculpa por eso - #notrase a sí mismo: no responda preguntas viendo "Die Hard 3" otra vez;) –

Cuestiones relacionadas