[英]dart-polymer update polymer dom elements
我正在使用此模板創建一個通知條目列表,該列表在第一次運行時效果很好。
NoticeList nle = querySelector('#noticeList');
nle.notices = notices;
但是我第二次調用此代碼時,該站點完全沒有改變。 我想念什么嗎?
謝謝
<polymer-element name="notice-list">
<template>
<ul id = "noticeEntrys">
<template repeat="{{notice in notices}}">
<li>
<notice-element notice={{notice}}></notice-element>
</li>
</template>
</ul>
</template>
<script type="application/dart" src="notice_list.dart"></script>
</polymer-element>
<polymer-element name="notice-element">
<template>
<div class="notice">
<textarea rows="8" readonly>{{notice.getText()}}</textarea>
<div class="controlls">
<button type="button" name="delete" on-click={{delete}}>Delete</button>
<button type="button" name="change" on-click={{change}}>Change</button>
</div>
</div>
</template>
<script type="application/dart" src="notice_element.dart"></script>
</polymer-element>
@CustomTag('notice-list')
class NoticeList extends PolymerElement {
NoticeList.created() : super.created() {
}
@published List<Notice> notices;
}
@CustomTag('notice-element')
class NoticeElement extends PolymerElement {
NoticeElement.created() : super.created() {
}
@published Notice notice;
void delete(Event e, var detail, Node target) {
Datamanager.removeNotice(notice);
Controller.updateListe();
}
void change(Event e, var detail, Node target) {
Controller.updateActiveElement(notice);
}
void setNotice(Notice n) {
notice = n;
}
}
編輯:我更新代碼與我第一次通過網絡服務獲取新數據時設置列表相同,並且新數據正確
static void noticesLoadedPolymerList(List<Notice> notices) {
NoticeList nle = querySelector('#noticeList');
nle.setNotices(notices);
}
Edit2:我添加了一個簡單的整數來顯示listsize @observable int listSize; 如果我分配了新列表,但顯示的內容沒有,則值會更改。
如果在NoticeList
中將notices
設置為新的List
實例,則它應該可以識別更改。 如果您在第一次嘗試中分配notices
,而僅在第二次嘗試中進行修改,則必須使您的notices
列表可觀察到var notices = toObservable([new Notice('notice1'), new Notice('notice2'), ...])
。
您尚未提供Notice
類的代碼。 可能有必要使您的Notice
類變得可觀察,例如:
注意類擴展了帶有Observable {@observable字符串文本的對象; }
這樣,Polymer會識別出僅通知實例的屬性是否發生更改(而不更改(添加/刪除) notices
列表)。
終於有時間解決問題了。
我的問題是我會像這樣開始聚合
initPolymer();
當我應該像這樣開始的時候
initPolymer().run(() {
//initialization and other stuff
}
有關此內容的更多信息, 請參見https://code.google.com/p/dart/issues/detail?id=15379
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.