你能试试这个吗?
<header>
<h2>Kendo MVVM with Marionette</h2>
<script type="text/html" id="sample-template">
<%= value1 %></br>
<label> Duration: </label>
<button id="myButton">Increase Duration</button>
</script>
</header>
<input id="Duration" type="text" data-bind="value: DurationValue" />
<div id="container"class="well">
<div>
而java脚本内容是:
var SampleView = Backbone.Marionette.ItemView.extend({
template : "#sample-template",
events :{
"click #myButton" : "IncreaseDuration"
},
IncreaseDuration : function () {
var value = parseInt(viewModelDuration.get("DurationValue"));
value = value+1;
viewModelDuration.set("DurationValue",value);
}
});
var viewModelDuration = new kendo.data.ObservableObject({
DurationValue: 1
});
var value = parseInt(viewModelDuration.get("DurationValue"));
var SampleModel = Backbone.Model.extend({
defaults : {
value1 : value, //"Value From viewModelDuration", How to assign??
}
});
var sampleModel = new SampleModel();
viewModelDuration.bind("change", function(e) {
value = parseInt(viewModelDuration.get("DurationValue"));
sampleModel.set({value1: value});
sampleView.render();
});
var sampleView = new SampleView({
model:sampleModel,
el : '#container'
});
sampleView.render();
kendo.bind($("#Duration"), viewModelDuration);
[答案]更新小提琴:
http://jsfiddle.net/KendoDev/jcDYN/15/