knockout.js 相关问题

Knockout.js是一个用于动态HTML的开源JavaScript库使用Model-View-Viewmodel(MVVM)模式。

使用数组中的最后一个图像

抱歉,如果格式错误或问题愚蠢,我是新手。我使用knockout js,通常用它来查找带有索引的图像并显示它,但是,我想知道是否可以确保它...

回答 1 投票 0

在Knockout JS中检查字符串,然后分割字符串值

我有以下数据绑定: $row().current_tracking 有时 $row().current_tracking 的值为,例如: 372424561624 有时 $row().current_tracking 的值带有两个

回答 1 投票 0

在Knockout JS中检查字符串,然后拆分值

我正在寻找一种使用 Knockout JS 检查字符串的方法。 我有以下数据绑定: $row().current_tracking 有时它的值为(示例):372424561624,有时(示例):

回答 1 投票 0

如何防止在执行淘汰绑定之前显示Html

我在我的 Html 中使用以下淘汰脚本: 一些东西 我遇到的问题是在

回答 5 投票 0

将 Handlebars.js 预编译模板与 KnockoutJS 结合使用

步骤 添加了运行时把手handbars.runtime.js html参考: 控制台...

回答 2 投票 0

JsonConvert.DeserializeObject 特殊字符 未终止的字符串。预期分隔符:

由于某种原因,当我的淘汰赛模型中有一个特殊字符并将其转换为json对象时,字符串在特殊字符应该在的位置结束,并且在反序列化时出现错误...

回答 5 投票 0

PDFMAKE:仅在 GULP 之后才在虚拟文件系统中找不到“Roboto-Regular.ttf”

我使用knockout/bootstrap/gulp 创建了一个简单的应用程序,它使用pdfMake.js 下载pdf。使用 VS2017 在调试模式下工作正常。发布并使用 gulp 后,运行时出现此错误:F...

回答 6 投票 0

为链接添加多个淘汰点击事件

我有一个具有多个绑定的链接: 我有一个具有多个绑定的链接: <a href="javascript:void(0);" data-bind="text:reportOutcomeDesc, attr:{id:reportOutcomeId}, event:{click:$root.editRepOutcome, click:$root.showRepGrid}"></a> 当我单击链接时,将调用 showRepGrid 函数,但不会调用 editRepOutcome。我怀疑这是一个语法问题,这就是为什么只调用最后一个函数的原因。 一次单击引发多个单击事件的正确语法是什么? 调用一键单击事件,并在该函数中调用两个子函数 editRepOutcome 和 showRepGrid。 <a href="javascript:void(0);" data-bind="click: function() { function1(); function2(); }"></a>

回答 2 投票 0

基于其他可观察的knockoutjs更新observableArray

每次使用单独的选择框时,我都需要更新 observableArray。问题出在酵母上...如果用户选择“Danstar”作为酵母类别,则“酵母品种&qu...

回答 1 投票 0

KnockoutJS SEO 友好吗

我的问题很简单:KnockoutJS SEO 友好吗?我有一个网站并大量使用 Knockout 数据模板,但我怀疑 Google 抓取工具是否会发现我的网站,因为 pa...

回答 2 投票 0

如何重定向到愿望清单控制器以在magento2中添加产品

我有一个问题让我被封锁,我需要帮助! 通过使用knockoutJs和控制器来获取form_key,我试图重定向到愿望清单以添加产品...

回答 1 投票 0

InvalidOperationException:以下部分已定义,但尚未由“/Views/Shared/UserLayout.cshtml”处的页面呈现

我正在尝试将 ASP.NET MVC 项目转换为 ASP.NET Core MVC。我已经完成了大部分工作,但陷入了一个奇怪的问题。 我的项目有一个视图User.cshtml和一个布局页面UserLayout.cshtml,...

回答 1 投票 0

Knockout 3.2:组件/自定义元素可以包含子内容吗?

我可以创建使用其中子标记的非空 Knockout 组件吗? 一个示例是用于显示模式对话框的组件,例如: 你是…… 我可以创建使用其中子标记的非空 Knockout 组件吗? 一个示例是用于显示模式对话框的组件,例如: <modal-dialog> <h1>Are you sure you want to quit?</h1> <p>All unsaved changes will be lost</p> </modal-dialog> 与组件模板一起使用: <div class="modal"> <header> <button>X</button> </header> <section> <!-- component child content somehow goes here --> </section> <footer> <button>Cancel</button> <button>Confirm</button> </footer> </div> 输出: <div class="modal"> <header> <button>X</button> </header> <section> <h1>Are you sure you want to quit?</h1> <p>All unsaved changes will be lost</p> </section> <footer> <button>Cancel</button> <button>Confirm</button> </footer> </div> 这在 3.2 中是不可能的,但在下一个版本中是可能的,请参阅 this commit 和 this test。 现在您必须通过 params 属性将参数传递给组件 定义您的组件以期望 content 参数: ko.components.register('modal-dialog', { viewModel: function(params) { this.content = ko.observable(params && params.content || ''); }, template: '<div class="modal">' + '<header>' + '<button>X</button>' + '</header>' + '<section data-bind="html: content" />' + '<footer>' + '<button>Cancel</button>' + '<button>Confirm</button>' + '</footer>' + '</div>' }); 通过 params 属性传递内容参数 <modal-dialog params='content: "<h1>Are you sure you want to quit?</h1> <p>All unsaved changes will be lost</p>"'> </modal-dialog> 参见小提琴 在新版本中您可以使用$componentTemplateNodes ko.components.register('modal-dialog', { template: '<div class="modal">' + '<header>' + '<button>X</button>' + '</header>' + '<section data-bind="template: { nodes: $componentTemplateNodes }" />' + '<footer>' + '<button>Cancel</button>' + '<button>Confirm</button>' + '</footer>' + '</div>' }); 在父组件中的使用: <modal-dialog><div>This div is displayed in the <section> element of the modal-dialog</div> </modal-dialog> 附注您可以手动构建最后版本的淘汰赛以使用上面的代码。

回答 1 投票 0

为什么在对淘汰视图模型中的项目进行重新排序时,此单选按钮会变为未选中状态?

我有一个简单的组件,允许输入一个问题和多个答案。可以通过单击向上/向下按钮对答案重新排序。我注意到,当答案重新排序时,

回答 1 投票 0

如何在knockout.js项目中有条件地显示模式对话框?

有一个工作表单,其中包含来自 knockout.js 项目的提交按钮。除此之外,表单还有一个提交按钮。 有一个工作表单,其中包含来自 knockout.js 项目的提交按钮。除此之外,该表单还有一个提交按钮。 <form id="formAddNote" data-bind="submit: addNotes" role="form" style="z-index:1041"> <button type="submit" class="btn" data-bind="enable: SubmitEnabled" style="margin- left:-10px;">Save Note</button> </form> 这是我的淘汰赛 addNotes 函数,它启动 ajax 调用以将数据保存到数据库: self.addNotes = function () { callAjax() } function callAjax(type, url, callback, data, errorCallback) { return $.ajax({ type: type, url: url, dataType: 'json', contentType: "application/json; charset=utf-8", data: data, success: callback, error: errorCallback }); } 这是我的模式对话框,带有“取消”和“继续”按钮: <div id="popUpModal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button class="close" aria-hidden="true" type="button" data-dismiss="modal">&times;</button> <h4 class="modal-title">Existing RadConsult Found</h4> </div> <div class="modal-body"></div> <div class="modal-footer"> <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button> <button class="btn btn-primary" type="button">Continue</button> </div> </div> </div> </div> 我想在ajax调用之前添加一个步骤,以显示一个模式对话框,通知用户注释是否已存在,并让用户选择取消中止或继续提交另一个注释。如何正确实现该对话框? Bootstrap 5 公开了模态的 JavaScript API,可用于以编程方式控制模态。请参阅 jsfiddle 示例:https://jsfiddle.net/martlark/hxm83Lqo/18/。示例: HTML: <div id="popUpModal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button class="close" aria-hidden="true" data-bind="click: clickCancel" type="button" data-dismiss="modal">&times;</button> <h4 class="modal-title">Existing RadConsult Found</h4> </div> <div class="modal-body"></div> <div class="modal-footer"> <button class="btn btn-secondary" type="button" data-bind="click: clickCancel" data-dismiss="modal">Cancel</button> <button class="btn btn-primary" type="button" data-bind="click: clickContinue">Continue</button> </div> </div> </div> </div> <button data-bind="click: clickOpenDialog"> Do the AJAX </button> <div data-bind="visible: mode()=='continue'"> Continue clicked </div> <div data-bind="visible: mode()=='cancel'"> Cancel clicked </div> 视图模型: class ViewModel { constructor() { this.mode = ko.observable('start'); const options = {}; this.myModal = new bootstrap.Modal(document.getElementById('popUpModal'), options) } clickOpenDialog(evt) { this.mode('confirm'); this.myModal.show() } clickContinue(evt) { this.mode('continue'); this.myModal.hide() } clickCancel(evt) { this.mode('cancel'); this.myModal.hide() } } viewModel = new ViewModel() ko.applyBindings(viewModel); 选项1 您可以为“继续”按钮提供一个 ID,并向其添加一个事件监听器。 <div class="modal-footer"> <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button> <button id="btnContinue" class="btn btn-primary" type="button">Continue</button> </div> 在 JavaScript 中: self.addNotes = function (data, event) { modal.show(); //Open modal. return false; //Suppress submit } $("#btnContinue").on("click", function() { callAjax(); }); 选项2 您可以处理模式的“hide.bs.modal”事件,并通过检查页面上哪个元素具有焦点来检测按下的按钮。 self.addNotes = function (data, event) { modal.show(); //Open modal. return false; //Suppress submit } modal.on("hide.bs.modal", function(event) { var $activeElement = $(document.activeElement); if ($activeElement.text() === "Continue") { callAjax(); } }); 在上面的示例中,“继续”按钮是通过其文本检测到的。或者,它可以是按钮 id、data-* 属性等..

回答 2 投票 0

SSO SAML 响应无法进入我的 Iframe

我正在使用 Shibboleth 进行 SSO 登录。对于测试,我使用 SAML 测试。我已经完成了所有 Shibboleth 安装和 IIS 配置。现在我的应用程序正在导航到 SAML 测试 l...

回答 0 投票 0

Uncaught ReferenceError: mozRTCSessionDescription is not defined

我有一个 ASP.NET MVC 应用程序(.NET Framework 4.6.2),它在 Knockout.js 上有一个前端,它也使用 signalR。 在我们将 Firefox 升级到版本 113.0 和 113.0.1 之前,该应用程序运行良好。该应用程序 ...

回答 1 投票 0

Show data-attributes from selected Radio-Button with knockout js

我是 knockoutjs 的新手,发现使用它有点困难。使用 jQuery 对我来说非常容易的事情,对淘汰赛根本不起作用...... 在 Magento 2 商店上,我想展示摘要...

回答 1 投票 0

如果切换一被关闭,然后切换二被用户关闭,那么切换一应该被打开

我对 knockoutjs 很陌生,我正在尝试创建两个切换。当用户关闭切换一然后关闭切换二时,应打开切换一,反之亦然。

回答 2 投票 0

在 Knockout.js 视图中,我什么时候将可观察对象作为函数调用?

我很难从 hasFocus 绑定的官方文档中遵循这个例子 看法: 姓名: 我很难从hasFocus绑定的官方文档中遵循这个例子 景色: <p> Name: <b data-bind="visible: !editing(), text: name, click: edit">&nbsp;</b> <input data-bind="visible: editing, value: name, hasFocus: editing" /> </p> <p><em>Click the name to edit it; click elsewhere to apply changes.</em></p> 视图模型: function PersonViewModel(name) { // Data this.name = ko.observable(name); this.editing = ko.observable(false); // Behaviors this.edit = function() { this.editing(true) } } ko.applyBindings(new PersonViewModel("Bert Bertington")); 我的困惑来自“编辑”可观察对象,它没有被声明为一个函数,但在视图中被调用,就像一个带有!editing()的函数,而不是像一个带有visible: editing和hasFocus: editing的函数。 我已经阅读了来自 knockoutjs.com 的文档,但无法弄清楚从视图中引用可观察对象的规则是什么。如果我有一个可观察的 foo,我什么时候在视图中将它引用为 foo() 以及什么时候将它引用为 foo? 有一个简单的解释:所有可观察量都是函数。所以,在这个例子中,editing 实际上是一个函数。您必须调用(或用 KO 术语“解包”)它来获取其当前值,这就是添加括号的原因。 当您将一个 observable 传递给默认绑定之一时,该绑定实际上会为您执行此解包(例如,请参阅 source 以了解可见绑定)。但是当你 negate 一个 observable 的值并想要使用它时,就像你对 !editing() 所做的那样,你需要先调用它来获取它的值。 !editing 的结果总是 false,因为 editing 是一个函数,并且总是计算为 true。而 !editing() 的结果是 editing 当前值的否定版本。 您需要将可观察变量作为函数调用[例如name() 和 editing()],当你需要采取一些行动时{例如不编辑(即!编辑())并将名称更改为大写[即name().toUpperCase()]} 在可观察变量的当前值上(即分别为 this.editing 和 this.name)。 参考:https://learn.knockoutjs.com/#/?tutorial=collections

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.