If this is necessary, then you can do this pretty easily with a custom binding.
Here is a binding that would set an existing observable using the element's innerText or create an observable if it doesn't exist.
ko.bindingHandlers.textWithInit = {
init: function(element, valueAccessor, allBindingsAccessor, data) {
var property = valueAccessor(),
content = element.innerText || element.textContent;
//create the observable, if it doesn't exist
if (!ko.isWriteableObservable(data[property])) {
data[property] = ko.observable();
}
data[property](content);
ko.applyBindingsToNode(element, { text: data[property] });
}
};
You would use it like:
<div data-bind="textWithInit: 'email_sended'"></div>
Note that the property name is in quotes, as the binding supports the observable not existing yet
Sample: http://jsfiddle.net/rniemeyer/kKBBj/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…