Skip to content

Instantly share code, notes, and snippets.

@zolo2hin
Created December 26, 2016 21:45
Show Gist options
  • Save zolo2hin/fdb92b163008e4f280287353cb32089b to your computer and use it in GitHub Desktop.
Save zolo2hin/fdb92b163008e4f280287353cb32089b to your computer and use it in GitHub Desktop.
New Twiddle
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
});
import Ember from 'ember';
export default Ember.Component.extend({
datasource: Ember.A(),
tagName: 'ul',
itemTag: 'li',
itemClass: 'item',
itemOpenedClass: 'item--open',
parent: null,
childItems: Ember.A(),
});
import Ember from 'ember';
export default Ember.Controller.extend({
});
import Ember from 'ember';
const eq = (params) => params[0] == params[1];
export default Ember.Helper.helper(eq);
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
title: DS.attr('string'),
parent: DS.belongsTo('category', {inverse: 'children'}),
children: DS.hasMany('category', {inverse: 'parent'})
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('main', { path: '/' });
});
export default Router;
$.mockjax({
url: '/categories',
type: 'GET',
status: '200',
dataType: 'json',
responseText: {
"data": [
{
"type": "categories",
"id": 1,
"attributes": {
"title": "Category 1",
},
"relationships": []
},
{
"type": "categories",
"id": 2,
"attributes": {
"title": "Category 2"
},
"relationships": {
"parent": {
"data": {
"type": "categories",
"id": 1
}
}
}
},
{
"type": "categories",
"id": 3,
"attributes": {
"title": "Category 3"
},
"relationships": {
"parent": {
"data": {
"type": "categories",
"id": 2
}
}
}
}
]
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').findAll('category');
}
});
{{log model}}
{{#tree-node datasource=model as |item|}}
{{#link-to '/' item.id}}
{{item.title}}
{{/link-to}}
{{/tree-node}}
{{#each datasource as |dataitem|}}
{{#if (eq dataitem.parent.id parent) }}
{{#tree-item register-as=this.childItems item=dataitem tagName=itemTag className=itemClass classOpened=itemOpenedClass classActive=itemActiveClass}}
{{yield this dataitem }}
{{#if dataitem.children}}
{{#tree-node parent=dataitem.id active=active actionsList=actionsList datasource=dataitem.children as |target subitem| }}
{{yield target subitem}}
{{/tree-node}}
{{/if}}
{{/tree-item}}
{{/if}}
{{/each}}
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.0",
"ember-data": "2.3.3",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0",
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment