[英]JsViews : two-way binding issue
当您在数据链接中绑定其他属性时,默认的bindng和trigger = true停止工作。 没有错误或任何明显的错误。 但这是行不通的。
默认绑定
在此示例( http://jsfiddle.net/BorisMoore/wch601L9/ )中,未明确设置属性(例如value {:amount})而绑定了“ amount”属性。 有用!
<td><input data-link="amount trigger=true" /></td>
如果通过添加其他绑定来更改此代码,则默认绑定“ amount”将不再显示在文本框中。
<td><input data-link="amount trigger=true disabled{:isSameAmountForAll}" /></td>
这里( http://jsfiddle.net/michaelsync/xzo15n0s/ )是我的BorisMoore示例的分支版本,我进行了更改以显示此场景。
我找到的解决方案是显式设置所有绑定的属性名称。
<td><input data-link="value{:amount} trigger=true disabled{:isSameAmountForAll}" /></td>
是已知问题吗?
触发器=真
如果在文本框中输入一些数字(示例示例http://jsfiddle.net/michaelsync/xzo15n0s/ ),则会看到总数没有得到更新。
我不确定如何解决此问题。 这也是一个已知问题吗?
如果这个问题不清楚,请随时告诉我。 谢谢!
注意:如果您想知道为什么要绑定两个属性,那么这是我正在测试的示例。 http://jsfiddle.net/michaelsync/078cazh8/2/
更新#1:
我现在正在调试JsViews源代码。 我修改了代码示例进行调试。
这是v1。 http://jsfiddle.net/michaelsync/tmwyhc7n/1/
仅具有一个绑定的模板
<script id="personTmpl" type="text/x-jsrender">
<input data-link="amount trigger=true" /> <br/>
</script>
<div id="placeholder" ></div>
JS
var myTemplate = $.templates("#personTmpl");
var people = [
{
name: "Adriana",
amount: 10,
isSameAmountForAll: false
}
];
myTemplate.link("#placeholder", people);
我在function parseTag(all, bind, tagName, converter, colon, html, comment, codeTag, params, slash, closeBlock, index)
处设置了断点
我只有命中,“ all”参数的值为“” {{:amount trigger = true}}“”
现在,我添加了以下其他绑定。
<script id="personTmpl" type="text/x-jsrender">
<input data-link="value{:amount} trigger=true disabled{:isSameAmountForAll}" /> <br/>
</script>
<div id="placeholder" ></div>
V2: http : //jsfiddle.net/michaelsync/tmwyhc7n/2/
然后我得到了两次成功,因为我绑定了“ amount”和“ isSameAmountForAll”。U看到解析中缺少“ trigger = true”。
所以..我在金额内移动了“ trigger = true”。
<script id="personTmpl" type="text/x-jsrender">
<input data-link="value{:amount trigger=true} disabled{:isSameAmountForAll}" /> <br/>
</script>
<div id="placeholder" ></div>
V3: http : //jsfiddle.net/michaelsync/tmwyhc7n/3/
更新#2:
解析似乎正确,但是ObserverAll不起作用。
我更改了以下代码以检测金额更改,但未触发该事件。
// http://stackoverflow.com/questions/25721180/summary-value-calculation-with-jsviews
var myTemplate = $.templates("#personTmpl");
var people = [
{
name: "Adriana",
amount: 10,
isSameAmountForAll: false
}
];
myTemplate.link("#placeholder", people);
$.observable(people).observeAll(function() {
console.log('weird stuff');
});
你需要
<input data-link="{:amount trigger=true:} disabled{:isSameAmountForAll}" />
http://www.jsviews.com/#linked-elem-syntax
要具有多个绑定,每个绑定都必须具有完整的语法(使用{...}
)。 对于双向绑定,它需要使用默认的绑定目标(属性)-因此请不要指定target属性:
{:amount trigger=true:}
。
对于单向绑定,您可以指定其他目标,例如disabled
:
disabled{:isSameAmountForAll}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.