Comments (8)
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.
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.
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.
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.
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.
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.
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.
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)
- model->DOM for radio doesn't check the radio at load of the page
- Appending to a new container doesn't fully remove from former parent container
- How to bind a subproperty? HOT 1
- More info in model change event HOT 4
- Zero value in model is not visible HOT 1
- data-bind with class should not clobber the agility class of root element HOT 2
- Append html element to parent containers view context
- Serialize agility object HOT 3
- Data binding default model values on first initialization HOT 1
- [enhancement] Add missing bower.json.
- Wrap agility around an existing DOM container/element
- Bind Agility Object to DOM element in page HOT 3
- feature request
- Is this project being maintained/branched elsewhere? HOT 4
- Is it possable to add if judgement,just like [ng-if].
- Is it possable to add repeat function and repeat callback,just like [ng-repeat].
- agilityjs.com was shutdown HOT 2
- COPYRIGHT INFRINGEMENT
- Unable to extend 'user_defined_property' when extending an existing prototype using $$()
- Multiple binds? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from agility.