0

データ バインディングに jsviews を使用しています。

私のテンプレート

<script id = "ProfileTemplate" type="text/x-jsrender">
<input data-link="userVO.first_name" type="text">
<input type="reset" value="Reset" onclick="this.form.reset();">
</script>

マイフォーム

<form name="profile-form" id="profile-form" action="profile.html">
<div id="flightEditDetail"></div>`enter code here`
</form> 

<script>
var template = $.templates("#ProfileTemplate");
template.link("#flightEditDetail", profileJSON);
</script>

テンプレートは値を正しくバインドします。テキスト フィールドの値を変更し、リセット ボタンをクリックしました。テキスト フィールドは空になりますが、ページの読み込み時にレンダリングされた値が必要です。

jsviews data-link で reset() 関数が正しく動作しないのはなぜですか?

4

1 に答える 1

2

reset() will revert the the intial/default value set in the value property: <input value="initialValue" />

For your case you could set the 'statically defined' value to the initial data value:

<input data-link="userVO.first_name" type="text" value="{{:userVO.first_name}}"/>

or better - attribute encode the initial value to avoid injection attacks:

<input data-link="userVO.first_name" type="text" value="{{attr:userVO.first_name}}"/>

The result is that the user will see the original value. However the reset action will only change the UI value, not the value in your underlying data that you are linking to. (See http://bugs.jquery.com/ticket/11043 for a related issue/concern in jQuery). So you would probably be better off not using reset() but instead cloning your initial data, and using $.observable(userVO).setProperty(originalUserVO) to revert.

于 2014-01-18T05:38:21.147 に答える