- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我遇到了以下情况。我有一个 with
block 分配给一个属性。当此属性为 null 时,内容不存在。但是,当放置属性标记时,应该生成。
HTML:
<!-- ko with: Gallery -->
<div class="GalleryMain">
<a href="#" data-bind="attr: {href: Current.Zoomed}" class="cloud-zoom" id="TargetZoom">
<img data-bind="attr: {src: Current.Main}" alt="" />
</a>
<span data-bind="text: Current.Zoomed"></span>
<span data-bind="text: Current.Main"></span>
</div>
<!-- /ko -->
<a href="javascript:;" id="Do">Update property</a>
JavaScript:
function PrimaryViewModel() {
var self = this;
this.Gallery = ko.observable(null);
this.Exit = function() {
self.Gallery(null);
}
}
var Picture = (function() {
function _Constructor(input) {
this.Zoomed = ko.observable(input.Zoomed);
this.Main = ko.observable(input.Main);
this.Thumb = ko.observable(input.Thumb);
}
_Constructor.Width = 489;
_Constructor.Height = 835;
return _Constructor;
})();
function GalleryViewModel(data, current) {
var self = this;
this.Pictures = ko.observableArray($.map(data, function(input) {
return new Picture(input);
}));
var all = this.Pictures();
this.Current = ko.observable(all[0]);
for (var i = 0; i < all.length; i++)
if (all[i].Main == current)
this.Current(all[i]);
this.SetCurrent = function() {
self.Current(this);
}
}
$(function() {
var viewModel = new PrimaryViewModel();
$("#Do").click(function() {
var data = [{
"Zoomed": "Content/Big/1Z.jpg",
"Main": "Content/Big/1.jpg",
"Thumb": "Content/Images/Thumbs/1.jpg"},
{
"Zoomed": "Content/Big/2Z.jpg",
"Main": "Content/Big/2.jpg",
"Thumb": "Content/Images/Thumbs/2.jpg"},
{
"Zoomed": "Content/Big/3Z.jpg",
"Main": "Content/Big/3.jpg",
"Thumb": "Content/Images/Thumbs/B1.jpg"},
{
"Zoomed": "Content/Big/4Z.jpg",
"Main": "Content/Big/4.jpg",
"Thumb": "Content/Images/Thumbs/3.jpg"},
{
"Zoomed": "Content/Big/15.jpg",
"Main": "Content/Big/5.jpg",
"Thumb": "Content/Images/Thumbs/B2.jpg"}];
viewModel.Gallery(new GalleryViewModel(data, "Content/Big/1.jpg"));
});
ko.applyBindings(viewModel);
});
按下 Update property
按钮后,正在生成 html 但没有绑定(bind)发生。请帮助我。
最佳答案
我已经解决了我的问题。陷阱真的隐藏得很好,就像“JavaScripting”时总会发生的那样。
<span data-bind="text: Current.Zoomed"></span>
<span data-bind="text: Current.Main"></span>
它试图捕获 Current
可观察对象的 Zoomed
属性。
<span data-bind="text: Current().Zoomed"></span>
<span data-bind="text: Current().Main"></span>
添加括号会提取包含 Zoomed
属性的目标对象。
关于javascript - knockout 不绑定(bind)值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9426998/
我想认真学习更多关于 ES6 的知识。我一直在网上做一些例子,虽然我得到了大部分例子,但有时我什至不知道从哪里开始。请注意,我对这个 ES6 和 Knockout 的东西 super 菜鸟,想通过从他
我正在使用 knockout.mapping 将我的 javascript 对象转换为可观察到的 knockout 。在这个 javascript 对象内部是一个嵌套对象,并且这个嵌套对象正在被转换,
我正在用 Kendo、Knockout 和 kendo-knockoutjs 库做一些实验。我想将 knockout View 模型与剑道数据源一起使用,并将其绑定(bind)到剑道网格小部件。 在剑
有谁知道现在当 jQuery.tmpl is not being actively developed or maintained anymore 时 Knockout 的默认模板引擎会发生什么? K
我面临一个问题,即添加新项目时计算的可观察数组未更新。 self.FilteredCityList = ko.computed(function() { var filteredCollectio
我想对数组中的多个属性使用 this fiddle 中的 ko.utils.arrayGetDistinctValues,因此我将数组映射到我想要的两个属性的数组 viewModel.justCate
我在使用 Knockout 的映射插件时遇到了一个奇怪的问题。 如果我通过映射填充一个 observable 数组,我将无法迭代该数组或获取其长度,即使 UI 已正确更新,该数组似乎也是空的。 你可以
所以我试图让 knockout 与 summernote 打得很好。它并没有真正起作用。我意识到这是因为 Summernote 使用了 而不仅仅是一个输入字段。 我的绑定(bind)是这样的: ko.
另一个我似乎无法找到帮助的 knockout 问题。 我基本上是在尝试实现级联下拉列表。前几天我请求帮助了解如何解析我的复杂 JSON(它来自 cakePHP Controller 。前几天我收到的帮
我在尝试使用映射插件将项目更新为 observableArray 的一部分时遇到问题。 我有以下代码 accounts.list = ko.mapping.fromJS(@(Html.Raw(Mode
有几件事我不明白。 根据 KO 文档(以及关于 SO 的许多帖子),在查询和编写 observable 时应该使用括号。但是在绑定(bind)子属性时,在我看来,是否使用括号并不重要。 = 都返回
我从 WCF 接收数据并将其绑定(bind)到表。我在这个论坛上得到了帮助,添加了一些计算字段,一切都很完美。我想在此表的页脚添加总计。我的页面的简单版本可以在 http://jsfiddle.net
我有一个使用 Knockout 显示过滤列表的页面。 View 模型有一个对象数组,以及一个使用 ko.utils.arrayFilter 来过滤数组的 ko.computed。 有时过滤会变得非常复
我正在使用 jquery quicksearch 来搜索由 knockout foreach 循环填充的表。 需要启动快速搜索元素 foreach 结束后 . 我尝试了几种方法,但到目前为止都没有成功
我正在尝试使用类似于 silverlight 中的数据表单的数据网格来创建数据表单功能。 我有一个 div 来显示从网格中选择的项目: $('#readDate').attr('data-bind',
我有一个带有分页功能的 View 模型,它维护 pageIndex 属性。 Viewmodel 有一个包含页面的页面数组。每个页面都有自己的 pageNumber 属性。 我的 View 模型的分页代
名称+复选框的单向绑定(bind)工作正常,但它最初不适用于单选按钮employeeTypeA,尽管它在viewmodel中的值为true,html显示单选按钮未设置,为什么会这样?
我正在尝试解决ko映射的一个小问题。场景是我的ViewModel基本上是对象的集合。每个对象都是通过json调用创建的,方法是: var ViewModel = ko.observableArray(
使用 computed 的主要区别是什么?函数和 subscribe在knockout.js 中的功能? 最佳答案 计算出的 observable 通常用于返回计算出的值。作为计算评估的一部分访问的任
我有带有项目验证的ko.observableArrays。用户可以将项目标记为已删除。将其标记为已删除时,我需要在该项目上禁用验证。 您如何动态禁用验证? 示例:http://jsfiddle.net
我是一名优秀的程序员,十分优秀!