2016-08-04 47 views
0

我在我的設計器中使用sf-list選擇器,如下所示。我看到我的產品列表,我可以選擇和排序。Sitefinity羽毛多個內容項目選擇器在設計器中的例外

<sf-list-selector sf-dynamic-items-selector sf-provider="properties.ProductProviderName.PropertyValue" sf-item-type="properties.ProductType.PropertyValue" sf-multiselect="true" sf-sortable="true" sf-master="true" sf-selected-ids="properties.ProductIds.PropertyValue" /> 

但是我得到的,當我按下保存在設計日誌文件異常:

請求的URL: https://localhost/Sitefinity/Services/Pages/ControlPropertyService.svc/batch/fc82280c-3055-6fae-9336-ff0000e88380/?pageId=230b270c-3055-6fae-9336-ff0000e88380&mediaType=0&propertyLocalization=0 內部異常----------- ----類型:System.Xml.XmlException, System.Xml,Version = 4.0.0.0,Culture = neutral, PublicKeyToken = b77a5c561934e089消息:來自命名空間''的預期結束元素'PropertyValue' 。從命名空間''找到元素'item'。 來源:System.Runtime.Serialization幫助鏈接:LineNumber上:0 LinePosition:0 SourceUri:數據: System.Collections.ListDictionaryInternal TargetSite:虛空 ThrowXmlException(System.Xml.XmlDictionaryReader,System.String, System.String,系統.String,System.String)HRESULT:-2146232000 堆棧跟蹤:在在System.Xml.XmlExceptionHelper.ThrowEndElementExpected System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader 讀者,字符串RES,字符串ARG1,字符串ARG2,字符串ARG3) (XmlDictionaryReader reader,String localName,String ns) at System.Xml.XmlBaseReader.ReadEndElement() at System.X ml.XmlBaseReader.ReadElementContentAsString() 在ReadWcfControlPropertyFromJson(XmlReaderDelegator,XmlObjectSerializerReadContextComplexJson,XmlDictionaryString, XmlDictionaryString []) 在System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader,XmlObjectSerializerReadContextComplexJson上下文) 在System.Runtime.Serialization .Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract,XmlReaderDelegator讀取器) 在System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator 閱讀器,字符串名稱,串NS,類型的declaredType,DataContract & 數據合同) 在System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator 的XMLReader,的Int32 declaredTypeID,的RuntimeTypeHandle declaredTypeHandle, 字符串名稱,串NS) 在ReadArrayOfWcfControlPropertyFromJson(XmlReaderDelegator,XmlObjectSerializerReadContextComplexJson,XmlDictionaryString, XmlDictionaryString,CollectionDataContract) 的系統。 Runtime.Serialization.Json.JsonCollectionDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader,XmlObjectSerializerReadContextComplexJson上下文) 在System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(dataContract dataContract,XmlReaderDelegator讀取器) 在System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator 閱讀器,字符串名稱,串NS,類型的declaredType,DataContract & dataContract) 在System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator 的XmlReader,類型的declaredType,DataContract dataContract,String name, String ns) at System.Runtime.Serialization.Json.DataContractJsonSerializer。InternalReadObject(XmlReaderDelegator 的XMLReader,布爾verifyObjectName) 在System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator 讀卡器,布爾verifyObjectName,DataContractResolver dataContractResolver)

我沒有爲一個JSON或JS文件視圖。當我使用單個項目的變化時,選擇所有項目都很好。

回答

1

事實證明,sf-selected-ids屬性的值需要使用JSON數組格式。例如[productId1,productId2,productId3]。否則,後端服務將拋出該異常。但是,選擇器本身會將該字符串創建爲product1,product2,product3。即沒有括號。 (您可以在設計師的高級視圖中看到這一點)。

因此,這裏有詳細的步驟:

這裏是在設計視圖中選擇(DesignerView.Simple.cshtml):

<sf-list-selector sf-dynamic-items-selector sf-provider="properties.ProductProviderName.PropertyValue" sf-item-type="properties.ProductType.PropertyValue" sf-multiselect="true" sf-sortable="true" sf-master="true" sf-selected-ids="productIds" /> 

你需要設計師JS文件做JSON來回轉換。所以我將它保存在MVC /腳本/ [WidgetName] /designer-simple.json:(簡單是設計視圖的名稱)

(function ($) { 

    var designerModule = angular.module('designer'); 
    angular.module('designer').requires.push('sfSelectors'); 

    designerModule.controller('SimpleCtrl', ['$scope', 'propertyService', function ($scope, propertyService) { 

     $scope.feedback.showLoadingIndicator = true; 
     propertyService.get().then(function (data) { 
      if (data) { 
       $scope.properties = propertyService.toAssociativeArray(data.Items); 
      } 
     }, 
     function (data) { 
      $scope.feedback.showError = true; 
      if (data) 
       $scope.feedback.errorMessage = data.Detail; 
     }).finally(function() { 
      $scope.feedback.showLoadingIndicator = false; 
     }); 

     $scope.$watch('properties.ProductIds.PropertyValue', function (newValue, oldValue) { 
      if (newValue) {    
       $scope.productIds = JSON.parse(newValue); 
      } 
     }); 

     $scope.$watch('productIds', function (newValue, oldValue) { 
      if (newValue) {    
       $scope.properties.ProductIds.PropertyValue = JSON.stringify(newValue); 
      } 
     }); 

    }]); 

})(jQuery); 

最後,我在同一個加了DesignerView.Simple.json文件文件夾爲DesignerView.Simple.cshtml:

{ 
    "priority": 1, 
    "scripts": [  
     "client-components/selectors/common/sf-selected-items-view.js" 
    ], 
    "components" : ["sf-dynamic-items-selector"] 
} 

控件控件具有ProductIds屬性。其值將採用格式[productId1,productId2等]。我使用JSON解串器獲取控制器的一系列產品索引操作:

public class ProductListController : Controller 
    { 
     private string productProviderName = WebConfigurationManager.AppSettings["productProviderName"]; 
     private string productTypeName = WebConfigurationManager.AppSettings["productTypeName"]; 

     public string ProductIds { get; set; } 

     public string ProductType 
     { 
      get { return productTypeName; } 
      set { productTypeName = value; } 
     } 

     public string ProductProviderName 
     { 
      get { return productProviderName; } 
      set { productProviderName = value; } 
     } 

     public ActionResult Index() 
     { 
      var selectedProducts = string.IsNullOrEmpty(this.ProductIds) ? new Guid[0] : JsonConvert.DeserializeObject<Guid[]>(this.ProductIds); 

     // ... rest of your controller index action 


     }   
    }