使用Knockout.js单击SharePoint中的项目

使用Knockout.js单击SharePoint中的项目,sharepoint,knockout.js,csom,Sharepoint,Knockout.js,Csom,我正在尝试使用knockout.js显示SharePoint文档库的详细信息。我希望可以单击项目名称或URL。是否可以?我正在尝试下面的代码,但它没有格式化到URL链接 下面是源代码 <table id="tblEmployeeList" border="1"> <thead> <tr> <th>Name</th> <th>Design

我正在尝试使用knockout.js显示SharePoint文档库的详细信息。我希望可以单击项目名称或URL。是否可以?我正在尝试下面的代码,但它没有格式化到URL链接

下面是源代码

 <table id="tblEmployeeList" border="1">  
    <thead>  
        <tr>  
            <th>Name</th>  
            <th>Designation</th>  
            <th>Department</th>  
            <th>Location</th>  
        </tr>  
    </thead>  
    <!-- Iterating through every list item using foreach of KO -->  
    <tbody data-bind="foreach: Employees">  
        <tr>  
            <td data-bind="text: Name"></td>  
            **<td <a href="#" data-bind="attr: { href: Designation}, text: Designation"></a></td>**  
            <td data-bind="text: Department"></td>  
            <td data-bind="text: Location"></td>  
        </tr>  
    </tbody>  
</table>  

名称
任命
部门
位置

** 这似乎和我预期的一样有效。如果你看不到一个可点击的链接,也许你的css中有什么东西改变了样式

这是一个复制片段,但我删除了与api调用相关的代码:

var completeEmployeeList=null;
//用于保存字段值的类。
职能员工名单(姓名、职务、部门、地点){
var self=这个;
self.Name=名称;
自我指定=指定;
self.Department=部门;
自我定位=定位;
}
//视图模型-定义UI数据和行为的JavaScript
函数EmployeeListViewModel(){
var self=这个;
//与常规数组等价的可观测数组,
self.Employees=ko.observearray([]);
self.AddEmployees=职能(姓名、职务、部门、地点){
self.Employees.push(新员工名单(姓名、职务、部门、地点));
}
}
函数mainformation(){
completeEmployeeList=新的EmployeeListViewModel();
//检索SharePoint列表项
//retrieveListItems();
//测试值
完整的员工列表。添加员工(‘测试名称’、‘测试部门’、‘测试名称’、‘测试地点’);
//激活knockout.js
ko.应用绑定(完整员工列表);
}
main函数()

名称
任命
部门
位置

我看不出您的代码有任何问题。你说“它不是格式化到URL链接”是什么意思?谢谢Jason为我指出了正确的方向。在我更改了表的格式后,它现在可以工作了。
    ExecuteOrDelayUntilScriptLoaded(MainFunction, "sp.js");  
var completeEmployeeList = null;  

// Class used for saving the field values.  
function EmployeeList(name, designation, department, location) {  
    var self = this;  
    self.Name = name;  
    self.Designation = designation;  
    self.Department = department;  
    self.Location = location;  
}  

//  View Model - JavaScript that defines the data and behavior of your UI  
function EmployeeListViewModel() {  
    var self = this;  
    // observableArray equivalent of a regular array,  
    self.Employees = ko.observableArray([]);  
    self.AddEmployees = function (name, designation, department, location) {  
        self.Employees.push(new EmployeeList(name, designation, department, location));  
    }  
}  

function MainFunction() {  
    completeEmployeeList = new EmployeeListViewModel();  

    // Retrieve the SharePoint list items  
    retrieveListItems();  

    // Activates knockout.js  
    ko.applyBindings(completeEmployeeList);  
}  

function retrieveListItems() {  
    var clientContext = new SP.ClientContext.get_current();  
    var oList = clientContext.get_web().get_lists().getByTitle('Documents');  
    var camlQuery = new SP.CamlQuery();  
    camlQuery.set_viewXml("<View><RowLimit>10</RowLimit></View>");  
    this.collListItem = oList.getItems(camlQuery);  
    clientContext.load(collListItem);  
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));  
}  

function onQuerySucceeded(sender, args) {  
    var listItemInfo = '';  
    var listItemEnumerator = collListItem.getEnumerator();  
    while (listItemEnumerator.moveNext()) {  
        var currentItem = listItemEnumerator.get_current();  
        completeEmployeeList.AddEmployees(currentItem.get_item("Title"), currentItem.get_item("FileRef"), currentItem.get_item("Editor"),currentItem.get_item("File_x0020_Size"), currentItem.get_item("Modified"));  
    }  
}  

function onQueryFailed(sender, args) {  
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
}