English 中文(简体)
KnockoutJS - Bind only the initial Value
原标题:KnockoutJS - Bind only the initial value

是否只有利用KnockoutJS对可观测到的单体元素的最初价值加以约束?

我知道,你可以通过对不值得观察的财产具有约束力来实现这一点,但我不制造多余的财产,只是要持有另一个可观察财产的最初价值。

我试图这样做,但是没有结果——这种特性仍然随着每次变化而得到更新。

<input type="text" id="tbName" 
  data-bind="value:name, attr: {  data-initialnamevalue : ko.utils.unwrapObservable($data.name()) }" />
最佳回答

虽然我同意上文的第零21xxx段,但我猜测,如果你提供了一种内心方法,但没有任何更新方法,你可以采用一种具有约束力的习俗。

Not sure it s worth the effort versus just adding another property.

Here s a simple example of what I mean: http://jsfiddle.net/ZkFRu/3/

第1款对财产的现值具有约束力,第2款对初始价值具有约束力。 粉碎了 but子的不动产。

问题回答

你们可以直接与可观察到的价值挂钩,而不是通过增加母体来观察,以便在最大约束时注入这一价值。 在更新该要素时,该要素不会更新可观测到的内容,因为该约束力具有价值,而不是可观察到的价值(即它不知道如何称可观测的功能来确定其价值)。

<input type="text" id="tbName" data-bind="value: name()" />




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签