Comments (6)
First, nice to see you use id
function.
For the question, there are three different approaches.
1/ You are in the DOM, so you can, using jQuery syntax, just check if your child form is the last in its parent container. It‘s not “academically” clear, but quiet effective.
2/ You can have a function inside each child form, that have acces to top levels. This approach is more general.
{
data:{ listElts:[ /*elements of a list*/] },
ChildFormManifest:{/* here goes child form manifest*/},
GetRootList: function(){ return this.data.listElts},
ui:{
"#list":{
data:"listElts",
manifest: function(){
return $.extend(true, {}, this.ChildFormManifest, {GetRootList: this.GetRootList});
}
}
}
}
3/ Third approach is very similar to second, but you extend child manifest on lis init, that is faster, but less flexible. Kinda static binding.
{
data:{ listElts:[ /*elements of a list*/] },
ChildFormManifest:{/* here goes child form manifest*/},
GetRootList: function(){ return this.data.listElts },
ui:{
"#list":{
init: function (){ this.ChildFormManifest.GetRootList = this.GetRootList },
data:"listElts",
manifest: "this.ChildFormManifest"
}
}
}
So for 2 and 3 you have this.GetRootList()
function inside each child‘s form, which returns entire array with data. Comapring child form‘s data with this.GetRootList().last()
using ===
, you detect, if your child form is last in the list.
from jquery.my.
Hi,
thx for your input!
I have thought about the different ways to solve it. My solution was just like your 2) using GetContent() function on the parent and comparing the index in my 'id' function.
id: function(e, i) {
e.idx = i+1;
e.firstChild = i === 0;
e.lastChild = i === this.getContent().length - 1;
return 'c3-q-' + e.idx;
},
It works, but...
When the "Add row" button triggers an 'insert' event on the list, or a row is deleted, the items do not get re-rendered. Same problem with the other approaches. The only solution would be to hack everything into a single callback and recalculate the list items on every insert/removal.
How do you solve this issue? Have you come across this in the past?
from jquery.my.
the items do not get re-rendered
You mean rows are not deleted/inserted, or what? If one row has not changed, why should it re-render?
from jquery.my.
The new items are re-rendered, but the rest of the list does not notice the change. The previous "lastChild" still has the "lastChild" attribute, and I don't know how to propagate the event to all list items
from jquery.my.
Do you use .hash
function? It can be useful for your case, I hope.
It is used to indicate element has changed. Make it return different values if list length changed – and you will get total list re-render on add/remove, or it can depend on other events, or parent form state, or whatever.
By default, when you have not defined it explicitly, built-in hash function only changes when child form contents changed, it does not know anything about outside world. So make it know.
This default approach was chosen to avoid total list re-render on every single row changed/removed/added, that is surely ineffective for long lists.
You can also skip defining .hash
and make .id
function do the same – return value, dependent on list length – but this is less effective for several reasons and undesirable, if do not understand clearly, what you‘re doing.
See this example http://jquerymy.com/#CW-masterdeta – here you can drag items and see how numbers are changing during drag both in master and detail. It‘s much more tricky, but it‘s the shortset implementation of this kind of functionality I ever seen. So it can help you to go deep into things.
from jquery.my.
Thanks for the hint to 'hash' function when list length changes, I will try that!
Best regards
Chris
from jquery.my.
Related Issues (20)
- Styler corrupts @keyframes sections
- Cannot use Enter in textarea in nested form. HOT 2
- $.my.locale does not change default locale HOT 1
- 引入my.js报错 HOT 1
- isS is not a function HOT 1
- Internal radio events reach only first listener
- Modal issues HOT 1
- Data only updates once HOT 2
- Issue with browser autocomplete forms HOT 1
- Validation error message not working on custom validation function HOT 2
- isS is not a function HOT 5
- Awesome job !! HOT 1
- Support binding for inputs of type "tel" and "email" HOT 2
- List renderer drops rows, which hashes are like obj default methods ("constructor", "valueOf" etc)
- Detecting change in linked field HOT 2
- it could not run with sugar 2.0.4 HOT 2
- Identify which event caused the control to redraw/recalc (invoked bind function) HOT 2
- Nested form/list validation errors are not being cleared HOT 9
- does it support a grandson list form? HOT 2
- how to set a value HOT 3
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 jquery.my.