草庐IT

knockout-templating

全部标签

javascript - 如何将 jquery 效果应用于 Knockout.js 创建的元素

您好,我的View中有以下代码:但是我想为每个新元素添加jQuery效果,例如:$("#draggable").draggable();有什么方法可以订阅元素添加到此列表后发生的事件吗? 最佳答案 最好的方法是使用自定义绑定(bind)。ko.bindingHandlers.draggable={init:function(element,valueAccessor){$(element).draggable();}};在文档中阅读更多相关信息:http://knockoutjs.com/documentation/custom-b

javascript - knockout 绑定(bind) 'with' 别名 'as'

我一直在使用knockout并且熟悉'foreach'绑定(bind),我可以在其中使用别名'as'::“with”绑定(bind)有类似的东西吗?我已经用下面的代码试过了,但得到了一个错误:UncaughtReferenceError:Unabletoprocessbinding"with:function(){return{data:$root.profileUser,as:'profile'}}"PreferredName 最佳答案 正如您所演示的,as选项与foreach创建了一个持久的别名,您可以在子上下文中引用该别名。如

javascript - 如何使用 knockout 使窗口大小可观察

尝试对浏览器窗口做一些事情:是否可以使用Knockout使窗口大小($(window).width(),$(window).height())可见?如何将FUTURE添加的元素保持在窗口的中央?有什么可以使用jquerylive方法或knockout自定义绑定(bind)来完成的吗?感谢任何建议! 最佳答案 使它们可观察的唯一方法是将它们代理为可观察的属性。varyourViewModel={width:ko.observable(),height:ko.observable()};var$window=$(window);$win

javascript - AngularJS 指令 : compile template and watch scope

我在Angularjs上编写了一个非常复杂的应用程序。这已经大到让我感到困惑了。我对Angular进行了更深入的研究,发现我的代码很糟糕。我理解这个概念:module.directive('createControl',function($compile,$timeout){scope:{//scopebindingswith'='&'@'},template:'Templatestringwithbinded{{variables}}',link:function(scope,element,attrs){//Functionwithlogic.Shouldwatchscope.}我

javascript - 具有多个参数的 Knockout JS 中的扩展器

一个可以使用extenders在knockout.js中有多个参数示例:ko.extenders.currency=function(target,currencySymbol,position){varresult=ko.computed({read:target,write:function(newValue){varcurrent=target(),if(position=='left'){target(currencySymbol+target);}else{target(target+currencySymbol);}}}).extend({notify:'always'})

javascript - 将 ByteArray 从 Knockout.js 发布到 Web 服务

我是KnockoutJS的新手,到目前为止我一直在研究它,但我尽我所能无法在任何地方找到此信息,所以我希望社区能提供帮助!在我看来,我对文件输入有以下数据绑定(bind):Upload这是“foreach”div中列表的一部分,因此变量“ImageToUpload”对应于该列表中对象的属性。在我的ViewModel中,上传按钮调用saveImage(),我调用网络服务并将表单数据传递到.aspx页面:self.saveImage=function(MyObject,event){$.post("Service.aspx",MyObject,function(returnedData){

javascript - 使用 knockout 将对象添加到可观察数组

出于某种原因,我无法将对象传递给可观察数组。functionCalendarViewModel(){varself=this;self.event={name:ko.observable(""),adress:ko.observable(""),startTime:ko.observable(""),endTime:ko.observable("")}self.events=ko.observableArray([])self.addEvent=function(event){self.events.push(event);alert(self.events.length)alert(

javascript - 如何订购 knockout 绑定(bind)?

我正在使用knockout.js。我陷入了一个有点奇怪的境地(很难解释,但我正在努力,如果我不清楚,抱歉)。我在单个选择列表上使用自定义绑定(bind)和选项绑定(bind):ko.bindingHandlers.chosen={init:function(element,valueAccessor,allBindingAccessor,viewModel,bindigContext){varoptions=ko.utils.unwrapObservable(valueAccessor()||{});$(element).chosen(options);}};此处在运行时选择列表将填充

javascript - knockout JS "You cannot apply bindings multiple times to the same element"

我正在使用kendo移动应用程序构建器,我正在使用knockoutjs进行绑定(bind),但出现错误“您不能将绑定(bind)多次应用于同一元素”。我有两个包含绑定(bind)的javascript文件,在我的代码下面//Employee.js//functionEmployeeViewModel(){this.EmployeeName=ko.observable();this.EmployeeMobile=ko.observable();this.EmployeeEmail=ko.observable();}ko.applyBindings(newEmployeeViewModel

javascript - knockout 选中/取消选中所有组合框

我使用knockout将JSON对象映射到用户控件,我有一个单个复选框的列表,他们看起来像我有JsonObjectvarviewModel={IsEnabled1:ko.observable(true),IsEnabled2:ko.observable(true),IsEnabled3:ko.observable(false)};...ko.applyBindings(viewModel);我想添加将选中/取消选中所有其他复选框的全局复选框,我在JavaScript端进行了此更改,但全局复选框更新了UI部分,但它们来自单独复选框的数据未映射到JSON对象。全局复选框$("#Genera