2

Emberを使い始めたので、Ember.Viewのコンテンツ配列に配列2Dを追加する方法を尋ねたいですか?元

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のコンテンツ配列に追加したいと思います。本当にありがとう。

4

1 に答える 1

2

Ember.ObjectIconMeaning-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);
}

Emberバインディングを使用して、ビューに接続します。

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

http://jsfiddle.net/HUHnE/で完全な実例を作成しました

于 2012-05-20T13:57:14.467 に答える