Coder Social home page Coder Social logo

Comments (8)

individual11 avatar individual11 commented on July 4, 2024

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?

from agility.

quartzo avatar quartzo commented on July 4, 2024

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>');

from agility.

individual11 avatar individual11 commented on July 4, 2024

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'));

from agility.

quartzo avatar quartzo commented on July 4, 2024

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>

from agility.

individual11 avatar individual11 commented on July 4, 2024

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'));

from agility.

quartzo avatar quartzo commented on July 4, 2024

The documentation says clearly:

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

from agility.

individual11 avatar individual11 commented on July 4, 2024

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.

from agility.

arturadib avatar arturadib commented on July 4, 2024

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!

from agility.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.