[英]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.