Polymer 2.0:如何通过id访问合成器?

时间:2017-10-03 20:37:12

标签: polymer

我已经从Polymer 1.0转换了我的代码(在1.0中工作)。

现在,控制台在通过其id访问iron-element期间仅报告null或错误。我不明白为什么。你能救我吗?

application.properties

在1.0中,我强烈使用<link rel="import" href="/bower_components/polymer/polymer.html"> <link rel="import" href="/bower_components/iron-ajax/iron-ajax.html"> <dom-module id="my-ajax"> <template> <iron-ajax id="req" method="{{method}}" url="{{url}}" handle-as="{{returnType}}" content-type="{{contentType}}" params="{{queryString}}" on-response="_handleResponse" on-error="_handleError"> </iron-ajax> </template> <script> class MyAjax extends Polymer.Element { static get is() { return 'my-ajax' } static get properties() { return { method: { type: String, value: "GET", notify: true }, ... datas: { type: Object, notify: true } } } constructor() { super(); } ready() { console.log(document.querySelector('#req')) console.log(document.querySelector('req')) console.log(this.$.req) } ... } customElements.define(MyAjax.is, MyAjax) </script> </dom-module> 来访问元素而没有问题。

1 个答案:

答案 0 :(得分:1)

当覆盖任何lifecycle callbacks(包括 private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "Categories") { String catids = dataGridView1.CurrentCell.Value.ToString(); Product p = (Product)productBS.Current; //DataRow dataRow = ((DataRowView)bindingSource1.Current).Row; p.Categories.Clear(); String[] catstrings = catids.Split(','); foreach (var cs in catstrings) { int catid = 0; int.TryParse(cs, out catid); if (catid != 0) { // Find this cat list in the BS and change it p.Categories.Add(_db.Categories.Find(catid)); } } e.Value = p.Categories; e.ParsingApplied = true; } } )时,请务必调用ready()等效内容。在这种情况下,您需要调用super.ready()来正确设置自动节点绑定。

super