knockoutjs中的双向绑定(Two way binding in knockoutjs)
我刚刚开始使用knockoutjs。 在下面的代码中我只想尝试双向绑定DIV的宽度。
var ViewModel = function () { this.width = ko.observable(7); }; ko.bindingHandlers.widthBinding = { init: function (element, valueAccessor, allBindingsAccessor, viewModel) { var div = $(element); var value = valueAccessor(); var Width = ko.utils.unwrapObservable(value); div[0].style['width'] = Width + "px"; }, update: function (element, valueAccessor, allBindingsAccessor, viewModel) { var value = valueAccessor(); var Width = ko.utils.unwrapObservable(value); div[0].style['width'] = Width + "px"; } }; $("#contentDiv").enableResize(); ko.applyBindings(new ViewModel()); <input data-bind="value: width" /> <div id="contentDiv" data-bind="widthBinding : width" >
在上面的代码中,我有两个UI元素,一个是文本输入,另一个是DIV。我们可以在运行时调整DIV的大小。 如果我在文本输入中输入一些数字将适用于DIV的宽度,那就行了。 同时,如果我在运行时调整DIV大小,则意味着其宽度应反映在文本输入中。 有没有办法做到这一点?
I just now start using knockoutjs. In below code am just trying to bind DIV's width in two-way.
var ViewModel = function () { this.width = ko.observable(7); }; ko.bindingHandlers.widthBinding = { init: function (element, valueAccessor, allBindingsAccessor, viewModel) { var div = $(element); var value = valueAccessor(); var Width = ko.utils.unwrapObservable(value); div[0].style['width'] = Width + "px"; }, update: function (element, valueAccessor, allBindingsAccessor, viewModel) { var value = valueAccessor(); var Width = ko.utils.unwrapObservable(value); div[0].style['width'] = Width + "px"; } }; $("#contentDiv").enableResize(); ko.applyBindings(new ViewModel()); <input data-bind="value: width" /> <div id="contentDiv" data-bind="widthBinding : width" >
In the above code i have two UI elements, one is Text Input and another one is DIV.And we can able to resize that DIV during run time. If i enter some number in text input means that will apply to DIV's width, that is working fine. At the same time if i resize the DIV during run time means its width should reflect in to the text input. Is there any way to do that?
原文:https://stackoverflow.com/questions/9017168
满意答案
米奇说,没有。
实际上,Microsoft实际上建议在许多小型装配体上创建较少数量的较大尺寸的装配体。 此早期问题提供了非常有用的信息和参考。
在你的情况下,你绝对应该测试加载时间并将大小保持在可接受的范围内,但似乎有更多的问题与创建大量小组件然后几个大组件相关联。
As Mitch says, no.
In fact it is actually recommended by Microsoft to create a smaller number of larger sized assemblies over many small assemblies. This earlier question provides very useful information and references.
In your case you should definitely test the load times and keep the size within acceptable limits, but it seems there are more problems associated with creating numerous small assemblies then a few large ones.
相关问答
更多动态加载DLL(Dynamic loading of DLL)
我的Dll大小通过引入大型开关盒而被吹掉,我如何减少我的Dll大小(MSVC C ++)?(my Dll size blown out by introducing large switch cases, how can I reduce my Dll size(MSVC C++)?)
什么是interop dll?(What is the interop dll?)
大DLL的问题?(problems with large DLL?)
性能问题 - 大型DLL和大型命名空间(Performance Problems - Large DLLs and Large Namespaces)
拥有多个DLL或单个大型DLL更好吗?(Is it better to have multiple DLLs or a single large DLL? [closed])
DLL和线程的问题(Problems with DLL & threads)
在使用我的DLL的应用程序中新/删除的奇怪问题(Strange problems with new/delete in an app that uses my DLL)
Fitnesse加载DLL的问题(Fitnesse problems loading dll)
DLL注入的最佳实践?(Best Practices for DLL Injection?)
相关文章
更多hibernate中OneToOne双向
hibernate中one2Many双向
hibernate中基于annotation(注解)的One2One双向
hibernate中基于annotation(注解)的one2Many双向
hibernate中基于annotation(注解)的many2many双向
JavaFx Main中怎么绑定Java类中的一个static变量呢?
spring mvc 页面传值到controller
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!