I have an ajax call that looks like so;
我有一个ajax调用,看起来是这样的;
success: function(data) {
//Return the results of the campaign data and populate the page.
$(data).find('campaign').each(function(i) {
campaignTitle = $(data).find('campaignTitle').text(),
campaignDesc = $(data).find('campaignDesc').text(),
campaignType = $(data).find('campaignType').text(),
campaignStatus = $(data).find('campaignStatus').text(),
campaignDuration = $(data).find('duration').text(),
campaignAuthor = $(data).find('whoCreated').text(),
campaignCreated = $(data).find('dateCreated').text(),
campaignTypeText = $(data).find('type').text(),
campaignDataID = $(data).find('typeID').text(),
campaignTypeName = $(data).find('typeName').text();
});
There are 2 records being returned but the only difference in the 2 is the Data ID which I get from a relational join in my table.
返回了两个记录,但这两个记录中唯一的区别是我从表中的关系连接中获得的数据ID。
My page is a single "record" with campaign details on it.
我的页面是一个带有竞选细节的“记录”。
For example, there is a title of the campaign.
例如,有一个运动的名称。
$('[name=campaignTitle]').empty().append(campaignTitle);
Now because its returning multiple records, its duplicating the campaign title which I understand that it will do that.
因为它返回了多个记录,它复制了竞选标题我知道它会这么做。
Since all of the data is the same in the rows except the data ID's, I only need to show everything one time and then I would keep the multiple ID's that it returns and do something with them.
由于除了数据ID外,行中的所有数据都是相同的,所以我只需要一次显示所有数据,然后保留它返回的多个ID并对它们进行处理。
I am trying to do something like so :
我试着这样做:
campaignTitle = $(data).find('campaignTitle')[0].text(),
This returns undefined.
这将返回未定义。
In short, I only want the campaign title to show one time, even if there are 5 records and I would do this by specifying which it as [0] since I know it would be the same as 1-4.
简而言之,我只希望活动标题显示一次,即使有5条记录,我将指定哪个为[0],因为我知道它将等于1-4。
1 个解决方案
#1
0
Why don't you return a DataSet or DataTable in your return and break down the value-pairs?
为什么不返回一个数据集或数据表并分解值对呢?
#1
0
Why don't you return a DataSet or DataTable in your return and break down the value-pairs?
为什么不返回一个数据集或数据表并分解值对呢?