Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert agility object anywhere on the DOM #32

Closed
quartzo opened this issue Jul 27, 2011 · 8 comments
Closed

Insert agility object anywhere on the DOM #32

quartzo opened this issue Jul 27, 2011 · 8 comments
Labels

Comments

@quartzo
Copy link
Contributor

quartzo commented Jul 27, 2011

Now you can only insert an agility object at the beginning (prepend) or at the end (append) of the list of the children defined for a DOM object.

$$.document.prepend(agilityObj, "table");

or

$$.document.append(agilityObj, "table");

I need to put the agility object in the middle, after the "tr" that defines the header of the table and before the "tr" that show totals of the table.

@individual11
Copy link

I thought you could. For instance, I built a test where I put it in the middle of my content like this:

$$.document.append(list, $('#content'));

Couldn't you do a similar selector with an ID or class in your table?

@quartzo
Copy link
Contributor Author

quartzo commented Jul 29, 2011

Let's say you have:

<table>
  <tr><td>1</td><tr>
  <tr><td>3</td><tr>
</table>

Now I want to put this in the middle:

<tr><td>2</td><tr>

Using jQuery I could use:

$('tr:eq(0)').after('<tr><td>2</td></tr>');

@individual11
Copy link

Give this a try:

<table>
   <tr><td>1</td></tr>
   <tr><td>3</td></tr>
</table>
var test = $$({}, '<td>2</td>');
$$.document.append(test, $('<tr />').insertAfter('table tr:first'));

@quartzo
Copy link
Contributor Author

quartzo commented Jul 29, 2011

I can only do that because in this case the "tr" has only one "td". :-)
I will have to complicate the example:

<tr><td>2</td><td>Product2</td></tr>

@individual11
Copy link

haha.. now I see it's just a cat and mouse game. For that, unless I miss something, you would change it in your view. Something like this:

<table>
   <tr><td>1</td><td>Product1</td></tr>
   <tr><td>3</td><td>Product3</td></tr>
</table>
var test = $$({productID:0, productName:''}, '<td data-bind="productID" /><td data-bind="productName" />');
var myTest = $$(test, {productID:2, productName:'Product2'})
$$.document.append(myTest, $('<tr />').insertAfter('table tr:first'));

@quartzo
Copy link
Contributor Author

quartzo commented Jul 29, 2011

The documentation says clearly:

// INVALID CODE!! (more than one root elements)
var obj = $$({}, '<div>hey there</div> <button>OK</button>');
$$.document.append(obj);

@individual11
Copy link

Yeah, you're right. It doesn't throw an error on any of my tests, but would probably freak out if you start doing anything heavy with the controller. I was more or less using it like a template. The problem is you can't select empty space and pass it as as the "selector" to put the root element. That's why I halfed it by creating the root element on the fly, but the controller won't recognize that.

Probably would be nicer if you could call the append method directly on a JQuery object, then it wouldn't matter.

@quartzo quartzo closed this as completed Jul 29, 2011
@quartzo quartzo reopened this Jul 29, 2011
@arturadib
Copy link
Owner

Hey guys, thanks for the brainstorming here. For completeness, I think it makes sense to have before() and after() methods. jQuery needed it, and we'll probably need it quite a bit too.

I've merged Fabio's (@quartzo) work, added some unit tests, and added a few touch-ups.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants