我已經在淘汰賽js.I中添加了新屬性到映射對象中。我可以訪問表中添加的屬性。但是當我裝一個目的是另一種觀點認爲它並沒有顯示增加的屬性,但我可以在UI訪問映射屬性將屬性添加到使用映射插件映射的ko模型
function Ticket(jsTicket){
var self = this;
ko.mapping.fromJS(jsTicket, {}, this);
this.company = "Gover";
this.formattedDate = moment(self.date(),"YYYY-MM-DDTHH:mm:ss").format("MM-DD HH:MM");
//This method call to another page, I could access js attribute in that UI but
// couldn't access manually added attributes,what would be the solution to this
this.getRunTicket = function(){
servicet.getTicket(self);
}
}
html頁面
<div data-role="page" id="rticketDetailsPage" data-theme="b">
<div data-role="content" data-theme="b" data-position="fixed">
<!-- mapped attribute from JS -->
<p>NO : <span data-bind="text: ticketNumber()"></p>
<!-- Manually added attributes -->
<p>Date : <span data-bind="text: formattedDate()"></p>
<p>Company : <span data-bind="text: company()"></p>
</div>
</>
Data grid Model
function DataGrid(){
var self = this;
self.dataGrid = ko.observableArray();
self.addTicketToGrid = function(ticket){
self.dataGrid.push(ticket);
}
}
數據網格的HTML
<tbody data-bind="foreach : dataGrid">
<tr>
<td><span data-bind="text : number(),click: getTicket"></span></td>
<!-- formatted date is manually added attribute,displays in grid-->
<td><span data-bind="text : formattedDate()></span></td>
<td><span data-bind="text : operatorName()"></span></td>
</tr>
</tbody>
爲什麼我無法在該範圍內手動添加添加的屬性?
預先感謝您
謝謝,現在正在工作 – ExCode