I’m trying to understand PubSub with a very simple example. In my fiddle, I have a simple input element. How do I keep my model.prop updated with the value of the input field?
Fiddle
<button>update</button>
<input type="text" value="10" /> <br />
<label></label>
var model = function(){
var p1 = $('input').val();
return {
prop: p1
}
}();
$('button').click(function(){
$('label').text(model.prop)
})
Try this:
This works because instead of defining a scalar value for the
propproperty, you define a function and get that result. As such each time you call the property it is dynamically updated with the value in the text field. See http://jsfiddle.net/CHvFk/4/.