2012-05-20 62 views
2

我開始使用Ember,所以我想問如何將數組2D添加到Ember.View的內容數組中? E.x將數組2D添加到Ember的內容數組中。查看

var IconMeaning = { 
OK: ['theme/dark/images/providers/ok.png', 'OK', 'Both'], 
Cancel: ['theme/dark/images/providers/delete.png', 'Cancel', 'Both'], 
Edit: ['theme/dark/images/providers/edit.png', 'Edit', 'AdminOnly'], 
Save: ['theme/dark/images/providers/save.png', 'Submit,Save', 'AdminOnly'], 
Add: ['theme/dark/images/providers/plus_blue.png', 'Add,Create,Insert', 'Both'], 
Remove: ['theme/dark/images/providers/remove.png', 'Remove,Delete', 'Both'], 
Next: ['theme/dark/images/providers/next.png', 'Next,Continue', 'Both'], 
Previous: ['theme/dark/images/providers/previous.png', 'Back,Previous', 'AdminOnly'], 
Up: ['theme/dark/images/goback.png', 'Up a Level', 'Both'], 
Info: ['theme/dark/images/providers/info.png', 'More Information', 'Both'], 
Public: ['theme/dark/images/public.png', 'Make,Active/Public', 'AdminOnly'], 
Private: ['theme/dark/images/private.png', 'Make,Inactive/Private', 'AdminOnly'], 
Calendar: ['theme/dark/images/calendar.png', 'Select Date', 'AdminOnly'], 
Download: ['theme/dark/images/providers/download.png', 'Download', 'Both'], 
Reload: ['theme/dark/images/providers/reload.png', 'Reload,Refresh', 'AdminOnly'], 
Print: ['theme/dark/images/providers/print.png', 'Print', 'Both'], 
Unlink: ['theme/dark/images/providers/unlink.png', 'Unlink,Unregister', 'AdminOnly'], 
AddToCart: ['theme/dark/images/providers/plus_green.png', 'Add to Cart', 'Both'], 
Checkout: ['theme/dark/images/providers/checkout.png', 'Checkout', 'Both'], 
Help: ['theme/dark/images/providers/help.png', 'Help', 'Both'], 
VideoHelp: ['theme/dark/images/providers/helpbutton.png', 'Video Help', 'Both'] 

}

我想將它們添加到Ember.View內容數組。非常感謝。

回答

2

您可以爲IconMeaning-Object的每個「行」創建一個Ember.Object,其中包含您的鍵和值數組。然後使用Ember.ArrayController,推動全行到其內容陣列pushObject

App.controller = Ember.ArrayController.create({ 
    content: [] 
}); 

for (var propertyName in IconMeaning) { 
    var emberObj = Ember.Object.create({ 
     key: propertyName, 
     values: IconMeaning[propertyName] 
    }); 
    App.controller.pushObject(emberObj); 
} 

使用灰燼綁定連接到您的看法:

App.view = Ember.View.extend({ 
    contentBinding: 'App.controller' 
}); 

我在http://jsfiddle.net/HUHnE/

+0

創建一個完整的工作示例現在這是額外的一英里,請投這個人。 –