1
我正在使用agilityjs作爲客戶端mvc框架。我有一種情況,我有一個div元素,應該顯示從服務器端檢索的商家列表,並將其作爲模型放在客戶端。如何將動態數組模型屬性綁定到agilityjs對象的視圖
var merchants = //retrieve merchants from server as json array;
var merchantsWrapper = $$({'merchants':merchants},'<div id="merchants-wrapper"></div>');
現在我需要的merchants
模型屬性綁定的方式來綁定到merchants-wrapper div
哪裏這個div應該顯示所有的商家。每個商家都是顯示在另一個原型merchant agility object
定義爲一個特定的佈局:
var merchantProto = $$({//model props}, '<div>rendering layout</div>');
我希望有一個機制,使merchants array
應該得到雙向綁定到merchants-wrapper div
和每個商家應根據merchant prootype
渲染,並在如果merchants
屬性通過排序或過濾來更改,則應該相應地更新視圖。
我有一個想法,我可以再使其在create
事件,做同樣的change:merchants
事件,但我不希望創建新的商戶對象,所以無論是應該有一個方法來清除merchants-wrapper
div的內容然後追加新的商家。
我覺得比起去jQuery的層並直接取出用'this.view。'這行('#merchants-wrapper「)。html(」「);''在'merchants'中每次改變HTML,你最好調用'this.empty()'。否則,您可能會遇到內存問題,因爲「商人」Agility對象是在每個「change」事件中創建的,但從未被正確銷燬。 – dodgethesteamroller 2013-06-04 01:32:54