[英]Polymer 1.0 data binding not working
I have the following polymer element: 我有以下聚合物元素:
The value of navigator.currentStep is not updating after someMethod is called. 调用someMethod后,navigator.currentStep的值不会更新。
<dom-module id="m">
<template>
Navigator step = <span>{{navigator.currentStep}}</span>
</template>
</dom-module>
Polymer({
is: 'm',
ready: function() {
this.navigator = new Navigator(1);
console.log(this.navigator.currentStep); // 1
},
someMethod: function() {
this.navigator.next();
console.log(this.navigator.currentStep); // 2
}
});
Output is always 输出始终
Navigator step = 1
导航器步骤= 1
But the following works 但是以下作品
<dom-module id="m">
<template>
Navigator step = <span>{{currentStep}}</span>
</template>
</dom-module>
Polymer({
is: 'm',
ready: function() {
this.navigator = new Navigator(1);
this.currentStep = this.navigator.currentStep; // 1
},
someMethod: function() {
this.navigator.next();
this.currentStep = this.navigator.currentStep; // 2
}
});
Call this.notifyPath('navigator.currentStep', this.navigator.currentStep)
. 调用
this.notifyPath('navigator.currentStep', this.navigator.currentStep)
。
See https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#set-path . 参见https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#set-path 。
Sometimes imperative code needs to change an object's sub- properties directly.
有时命令式代码需要直接更改对象的子属性。 As we avoid more sophisticated observation mechanisms such as Object.observe or dirty-checking in order to achieve the best startup and runtime performance cross-platform for the most common use cases, changing an object's sub-properties directly requires cooperation from the user.
由于我们避免使用更复杂的观察机制(例如Object.observe或dirty-check)来针对最常见的用例实现最佳的启动和运行时性能跨平台,因此更改对象的子属性直接需要用户的配合。
Specifically, Polymer provides two API's that allow such changes to be notified to the system:
notifyPath(path, value)
andset(path, value)
, where path is a string identifying the path (relative to the host element).具体来说,Polymer提供了两个API,可将此类更改通知给系统:
notifyPath(path, value)
和set(path, value)
,其中path是标识路径的字符串(相对于host元素)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.