首页 新闻 会员 周边

在使用knockout + easyui 遇到的datetimebox的问题。

0
悬赏园豆:100 [已关闭问题] 关闭于 2014-07-10 16:37

虽然不满于easyui的效率,easyui的使用。但除了无奈,还是要解决问题的。其中datetimebox无法进行双向绑定。html的改变无法通知到后台。

使用的是<script type="text/html">

datetimebox的html写法:

<input class="z-txt easyui-datetimebox" style="width: 220px;" data-bind="dateboxtimeValue:form.HappenTime" data-options="required:true,showSeconds:false" />

在js中创建绑定的方式:

//value
ko.creatEasyuiValueBindings = function (o) {
o = $.extend({ type: '', event: '', getter: 'getValue', setter: 'setValue', fix: $.noop,formatter: function (v) { return v; }}, o);

var customBinding = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var jq = jqElement(element), handler = jq[o.type]('options')[o.event], opt = {};

//handle the field changing
opt[o.event] = function () {
handler.apply(element, arguments);
var value = jq[o.type](o.getter);
if (valueAccessor() == null) throw "viewModel中没有页面绑定的字段";
valueAccessor()(value);
};

//handle disposal (if KO removes by the template binding)
ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
jq[o.type]("destroy");
});

o.fix(element, valueAccessor);
jq[o.type](opt);
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
value = ko.utils.unwrapObservable(valueAccessor());
jqElement(element)[o.type](o.setter, o.formatter(value));
}
};
ko.bindingHandlers[o.type + 'Value'] = customBinding;
};

 ko.creatEasyuiValueBindings({ type: 'datetimebox', event: 'onSelect', formatter: com.formatTime });

 

希望大神们帮我看到。因为看到easyui中的datetimebox没有事件,无法通过控制事件的方式来通知变化。

还有如何在<script type="text/html">中如何使用script或css,谢谢。

 

anson_wang的主页 anson_wang | 初学一级 | 园豆:118
提问于:2014-05-20 11:17
< >
分享
所有回答(2)
0

ko 只能应用于普通的html控件绑定,或者专门针对ko封装的datetime插件,楼主放弃吧。

冲动 | 园豆:394 (菜鸟二级) | 2014-05-20 17:52
0

event: 'onChange',

M.Zero | 园豆:202 (菜鸟二级) | 2015-08-07 15:57

真的可以 感谢

支持(0) 反对(0) CsharpFish | 园豆:200 (初学一级) | 2015-11-25 14:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册