开发者

jQuery design question

I have a rails app, where I have 2 models, user and notice. A user has a single notic开发者_如何学Pythone. I'm using jQuery to implement the 'edit' and 'update' methods for notice.

In order to send the correct 'id' of the notice to my notice controller i've created a div tag in the view with the id of the notice, so that i can get the id of the notice using jQuery.

I was wondering whether this is the right way to go about implementing CRUD operations using jQuery(the having a div with the id of the notification part) ??

Any thoughts would be appreciated!

Thanks,

Punit


The Yes version:

In HTML DOM stuff (and jQuery selectors too, I think :) ) it is important not to have the same id attribute for more than one div, so for the future I would recommend adding a string or a character before the id, eg.:

<div id="not123254">...</div>

and getting it: var id=$(whatever).attr('id').substring(3);

substring with one parameter skips first n characters.

It is helpful when You have more than one source of ids on the page (things from different tables, etc.)

The No version: Some people use jQuery.data() for storing the id. I cannot compare the problems. For me the id is the default


I usually use a hidden span with id as innerHTML, or put it to js vars:

<script>
  notice_id = <%= bla %>;
</scipt>

it's easier with jQuery too this way...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜