我有一个输入元素绑定到一个淘汰观察:
<input type="text" data-bind="value: myText, valueUpdate: 'keyup'" />
Run Code Online (Sandbox Code Playgroud)
这会更新每个keyup上的observable.我现在想要在值更改时触发其他事件.
以下原则上做到了这一点:
this.myTextTrigger = ko.computed( function () {
console.log( this.myText() );
}, this );
Run Code Online (Sandbox Code Playgroud)
然而,它似乎有点笨重.它还会在模板的初始实例化时触发,我只想在此之后处理更改.是否存在基于可观察量变化触发事件的官方/更简单的方法?
我有一个选择框,其中的选项和选择通过Knockout.js处理.我想使用Materialise CSS来设置它的样式.
这对于初始显示选择框是正常的,并且当选项被添加到Knockout.js'选项'observableArray时,使用'optionsAfterRender'绑定到(重新)初始化后添加每个选项(浪费,但有效) .
删除选项时,Knockout.js不提供类似'optionsAfterRender'的任何内容,因此没有明显的方法可以触发Materialize CSS魔法的重新初始化.
问题:您可以看到任何非疯狂的选项吗?
码:
<select data-bind="
options: options,
optionsText: function(item) { return optionsText[item] },
value: displayedValue,
optionsAfterRender: function (option, item) {
setTimeout(function() {
$(option.parentElement).material_select();
}, 0);
}
">
</select>
Run Code Online (Sandbox Code Playgroud)
('setTimeout'是必要的,否则不会选择所选的选项.)
我正在使用Sphinx编写一些文档。
有没有一种方法可以格式化不属于TOC的页面中的标题?理想情况下,具有反映格式的某些层次结构?
例如,我想做
My page TOC heading
===================
Subheading (not in TOC, and should be formatted e.g. smaller than the heading)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sub-subheading (not in TOC, and formatted e.g. smaller than the subheading)
###########################################################################
Run Code Online (Sandbox Code Playgroud)
也欢迎任何其他有关如何标记文本的建议,以使文本对读者来说更具结构化外观。
我想要一个背景渐变,例如
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(2, 126, 174, 0.9))
Run Code Online (Sandbox Code Playgroud)
在我的文件的主体上,延伸到整个身体的高度 - 并与身体滚动.
运用
background-attachment: fixed;
Run Code Online (Sandbox Code Playgroud)
我得到了(视口的)整个高度,但它保持固定.
background-attachment: scroll;
Run Code Online (Sandbox Code Playgroud)
让我滚动,但它只是延伸到视口高度.
任何方式来获得两者?
编辑:
正如Boltclock指出的那样,我确实通过基本测试页面上的"background-attachment:scroll"得到了预期的行为.
同
<body>
<div id="stretch">Content</div>
</body>
Run Code Online (Sandbox Code Playgroud)
和
body {
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(2, 126, 174, 0.9));
}
#stretch {
height: 2000px;
}
Run Code Online (Sandbox Code Playgroud)
一切正常:渐变遍布整个身体(身体高2000像素),并滚动内容.
然后我补充说
html,
body {
height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
这是页面所基于的基本模板所做的事情.
为了让身体再次扩张,我补充说
height: auto;
Run Code Online (Sandbox Code Playgroud)
身体恢复到2000px的高度.
但是,渐变保持在HTML高度 - 然后重复.
我在这里错过了什么?
我使用KnockoutJS从数组填充列表:
<div data-bind:"foreach: list">
<input type="text" data-bind="value: myText" />
</div>
function ViewModel() {
self.list = ko.observableArray([
new listItem("sample text")
]);
};
function listItem (text) {
this.myText = text;
};
Run Code Online (Sandbox Code Playgroud)
我可以像这样为我输入的各个实例分配一个id
<input data-bind="attr: { id: $index } ...
Run Code Online (Sandbox Code Playgroud)
如何从listItem函数中访问此索引?我希望能够做类似的事情
function listItem (text) {
this.myText = text;
this.index = $index;
};
Run Code Online (Sandbox Code Playgroud)
为了进一步处理使用它.
knockout.js ×3
css ×1
css3 ×1
html ×1
indexing ×1
javascript ×1
markup ×1
materialize ×1
observable ×1
triggers ×1