88991534 2012-11-14
代码如下:
$(function () { var viewModel = function () { var self = this; self.text = ko.observable(1); }; ko.applyBindings(new viewModel()); });
代码如下:
<div data-bind='text:text'></div>
代码如下:
$(function () { var viewModel = function () { var self = this; self.text = ko.observable(); }; ko.applyBindings(new viewModel()); });
代码如下:
<div data-bind='with:text'> <div data-bind="text:property"></div> </div>
代码如下:
//雾里看花 Q:397386036 ko.bindingHandlers.ext = { update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { var value = ko.utils.unwrapObservable(valueAccessor()); for (var handler in value) { if (value.hasOwnProperty(handler)) { if (typeof viewModel[value[handler]] == 'undefined') { viewModel[value[handler]] = ko.observable(); } ko.bindingHandlers[handler].update(element, function () { return viewModel[value[handler]]; }); } } } };
代码如下:
$(function () { var viewModel = function () { }; ko.applyBindings(new viewModel()); });
代码如下:
<div data-bind="ext:{text: 'text'}"></div> <!--事件 便于 测试--> <a href="javascript:void(0)" data-bind="click:function(){$data.text(1);}">更改text值</a>