JavaScript + XML

标签 javascript jquery xml

有一些 JavaScript 可以查看下面 XML 的“注释”部分,我正在尝试添加另一个规则,其中:“is-public”需要具有值:“true”。我尝试添加 public[count] = $j(this).find('is-public').text("true")(); 这似乎不起作用。谁能帮我吗?提前致谢

JAVASCRIPT:

$j(document).ready(function() {
    $j('#ticket_fields_NONE').attr("disabled", true);
  //Check to see if there isn't already a value
  if(!$j('input#ticket_fields_NONE').val()) {

    //setting the DOM Object to attach the queue to
    var para = $j("select#ticket_assignee_id");
        var roleID = new Array();
    var count = 0;
    var commentAuthor = new Array();
    var ticketCreated = new Array();
var public = new Array();

//beginning of queue
        para.queue("testQueue", function( next ){$j.get('/tickets/{{ticket.id}}.xml', 
            function(ticketCreateAt) {
                $j(ticketCreateAt).find('comment').each(function() {
                    ticketCreated[count] = $j(this).find('created-at').text();
    public[count] = $j(this).find('is-public').text("true")();
                    commentAuthor[count] = $j(this).find('author-id').text();
                    var timeUNIX = new Date();
                    timeUNIX.setISO8601(ticketCreated[count]);
                    ticketCreated[count] = Date.parse(timeUNIX)/1000;
                    //displays in the sidewidget it can be removed.
                    count++;
                });

XML:

 <ticket>
    <assigned-at type="datetime" nil="true"/>
    <assignee-id type="integer" nil="true"/>
    <base-score type="integer">720</base-score>
    <created-at type="datetime">2012-07-17T10:38:03+10:00</created-at>
    <current-collaborators nil="true"/>
    <current-tags>
    topic-general_site_tech-facebook_question training_tim via_contact_form
    </current-tags>
    <description>test</description>
    <due-date type="datetime" nil="true"/>
    <entry-id type="integer" nil="true"/>
    <external-id nil="true"/>
    <group-id type="integer" nil="true"/>
    <initially-assigned-at type="datetime" nil="true"/>
    <latest-recipients nil="true"/>
    <nice-id type="integer">218</nice-id>
    <organization-id type="integer" nil="true"/>
    <original-recipient-address nil="true"/>
    <priority-id type="integer">0</priority-id>
    <recipient nil="true"/>
    <requester-id type="integer">237738133</requester-id>
    <resolution-time type="integer" nil="true"/>
    <solved-at type="datetime" nil="true"/>
    <status-id type="integer">0</status-id>
    <status-updated-at type="datetime">2012-07-17T10:38:03+10:00</status-updated-at>
    <subject/>
    <submitter-id type="integer">214034168</submitter-id>
    <ticket-type-id type="integer">0</ticket-type-id>
    <updated-at type="datetime">2013-04-19T12:53:45+10:00</updated-at>
    <updated-by-type-id type="integer">0</updated-by-type-id>
    <via-id type="integer">5</via-id>
    <score type="integer">720</score>
    <problem-id nil="true"/>
    <has-incidents type="boolean">false</has-incidents>
    <comments type="array">
    <comment>
    <author-id type="integer">237738133</author-id>
    <created-at type="datetime">2012-07-17T10:38:03+10:00</created-at>
    <is-public type="boolean">true</is-public>
    <type>Comment</type>
    <value>test</value>
    <via-id type="integer">5</via-id>
    <attachments type="array"/>
    </comment>

最佳答案

如果您只想迭代公共(public)评论,请更改

$j(ticketCreateAt).find('comment')

$j(ticketCreateAt).find('comment:has(is-public:contains("true"))')

演示:Fiddle

关于JavaScript + XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16138825/

相关文章:

javascript - 表单中的 bootstrap3 工具提示

javascript - Chrome 扩展 - 获取用户在撰写邮件时输入的文本

html - 链接到另一个节点中的项目 (XSLT)

JavaScript - 通过在不同位置组合其他字符串来创建字符串

javascript - 为什么 Or 不能在 angularJs ng-pattern 中工作?

javascript - 所有键的键码值均返回为 229

javascript - Leaflet 放大镜插件 - 切换层

javascript - 在页面加载时一一加载 Bootstrap 列

xml - Groovy XmlSlurper : Find elements in XML structure

xml - xml 文件中的 Visual Studio TODO 注释到任务列表